问题
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