简体   繁体   English

如何在“详细信息”视图中启动JFileChooser?

[英]How can I start the JFileChooser in the Details view?

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

You can get the Action from the ActionMap: 您可以从ActionMap获取Action:

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. 首先,您需要获取JFileChooser具有的FilePane。 The only way I know how to do that is to traverse its components and then do an instanceof FilePane until you get it. 我知道如何做到这一点的唯一方法是遍历其组件,然后执行instanceof FilePaneinstanceof FilePane直到你得到它。 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);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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