How can I start the JFileChooser in the Details view?
Asked Answered
K

2

16

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

Kenji answered 30/4, 2013 at 5:6 Comment(0)
H
25

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);
Herculie answered 30/4, 2013 at 5:27 Comment(2)
Nice, that's probably a better way to do it. Actually, maybe you can help me with my problem over here: #16230026Kenji
is this still the solution in 2021? or is there a better or other way how to do it?Prejudicial
K
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:

    if (root instanceof FilePane) {
        FilePane filePane = (FilePane) root;
        Action viewTypeAction = filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS);
        viewTypeAction.actionPerformed(null);
    }
Kenji answered 30/4, 2013 at 5:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.