How can I start the JFileChooser in the Details view?

主宰稳场 提交于 2019-12-17 20:44:12

问题


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


回答1:


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);



回答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);
    }


来源:https://stackoverflow.com/questions/16292502/how-can-i-start-the-jfilechooser-in-the-details-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!