I would like my JFileChooser to start in details view, instead of the "List" view that it starts in. How do you do that?
            Asked
            
        
        
            Active
            
        
            Viewed 6,254 times
        
    2 Answers
24
            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);
        camickr
        
- 321,443
 - 19
 - 166
 - 288
 
- 
                    Nice, that's probably a better way to do it. Actually, maybe you can help me with my problem over here: http://stackoverflow.com/questions/16229526/how-do-you-remove-the-ctrlc-action-on-a-jfilechooser#comment23321430_16285866 – Daniel Kaplan Apr 30 '13 at 05:38
 - 
                    is this still the solution in 2021? or is there a better or other way how to do it? – Strubbl Jun 10 '21 at 21:23
 
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);
    }
        Daniel Kaplan
        
- 62,768
 - 50
 - 234
 - 356