I would like my JFileChooser to start in details view, instead of the "List" view that it starts in. How do you do that?
How can I start the JFileChooser in the Details view?
Asked Answered
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);
Nice, that's probably a better way to do it. Actually, maybe you can help me with my problem over here: #16230026 –
Kenji
is this still the solution in 2021? or is there a better or other way how to do it? –
Prejudicial
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);
}
© 2022 - 2024 — McMap. All rights reserved.