如何在“详细信息”视图中启动JFileChooser?

时间:2021-12-02 20:47:31

I would like my JFileChooser to start in details view, instead of the "List" view that it starts in. How do you do that?

我希望我的JFileChooser能够从详细信息视图开始,而不是从它开始的“列表”视图开始。你是如何做到的?

2 个解决方案

#1


12  

You can get the Action from the ActionMap:

您可以从ActionMap获取Action:

JFrame frame = new JFrame();
JFileChooser  fileChooser = new JFileChooser(".");
Action details = fileChooser.getActionMap().get("viewTypeDetails");
details.actionPerformed(null);
fileChooser.showOpenDialog(frame);

#2


2  

This is a little tricky and probably not officially supported, but I found out how to do this. First, you need to get the FilePane that the JFileChooser has. The only way I know how to do that is to traverse its components and then do an instanceof FilePane until you get it. Then this will start in Details view:

这有点棘手,可能没有得到官方支持,但我发现了如何做到这一点。首先,您需要获取JFileChooser具有的FilePane。我知道如何做到这一点的唯一方法是遍历其组件,然后执行FilePane的实例,直到你得到它。然后这将在详细信息视图中开始:

    if (root instanceof FilePane) {
        FilePane filePane = (FilePane) root;
        Action viewTypeAction = filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS);
        viewTypeAction.actionPerformed(null);
    }

#1


12  

You can get the Action from the ActionMap:

您可以从ActionMap获取Action:

JFrame frame = new JFrame();
JFileChooser  fileChooser = new JFileChooser(".");
Action details = fileChooser.getActionMap().get("viewTypeDetails");
details.actionPerformed(null);
fileChooser.showOpenDialog(frame);

#2


2  

This is a little tricky and probably not officially supported, but I found out how to do this. First, you need to get the FilePane that the JFileChooser has. The only way I know how to do that is to traverse its components and then do an instanceof FilePane until you get it. Then this will start in Details view:

这有点棘手,可能没有得到官方支持,但我发现了如何做到这一点。首先,您需要获取JFileChooser具有的FilePane。我知道如何做到这一点的唯一方法是遍历其组件,然后执行FilePane的实例,直到你得到它。然后这将在详细信息视图中开始:

    if (root instanceof FilePane) {
        FilePane filePane = (FilePane) root;
        Action viewTypeAction = filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS);
        viewTypeAction.actionPerformed(null);
    }