简体   繁体   中英

How can I start the JFileChooser in the Details view?

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

You can get the Action from the ActionMap:

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

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM