如何将JFileChooser标签“Look in:”更改为“Save in:”(不是标题)?

3
如何将JFileChooser中的标签“Look in:”更改为“Save in:”(不是标题)? 在此处您可以看到我想要更改的内容:

扩展文件选择器,然后修改字段? :p - EDToaster
嗯...使用了installUI(JComponent c)方法,这意味着我必须在JFileChooser当前的UI实现中寻找。也许已经有人做过了。 - Ernestas Gruodis
3个回答

6
我找到了解决方案,也许对某些人有用:

我发现解决方法,也许对某些人有用:

JFileChooser chooser = new JFileChooser("Open");

//Set the text and language of all the components in JFileChooser
UIManager.put("FileChooser.openDialogTitleText", "Open");
UIManager.put("FileChooser.lookInLabelText", "LookIn");
UIManager.put("FileChooser.openButtonText", "Open");
UIManager.put("FileChooser.cancelButtonText", "Cancel");
UIManager.put("FileChooser.fileNameLabelText", "FileName");
UIManager.put("FileChooser.filesOfTypeLabelText", "TypeFiles");
UIManager.put("FileChooser.openButtonToolTipText", "OpenSelectedFile");
UIManager.put("FileChooser.cancelButtonToolTipText","Cancel");
UIManager.put("FileChooser.fileNameHeaderText","FileName");
UIManager.put("FileChooser.upFolderToolTipText", "UpOneLevel");
UIManager.put("FileChooser.homeFolderToolTipText","Desktop");
UIManager.put("FileChooser.newFolderToolTipText","CreateNewFolder");
UIManager.put("FileChooser.listViewButtonToolTipText","List");
UIManager.put("FileChooser.newFolderButtonText","CreateNewFolder");
UIManager.put("FileChooser.renameFileButtonText", "RenameFile");
UIManager.put("FileChooser.deleteFileButtonText", "DeleteFile");
UIManager.put("FileChooser.filterLabelText", "TypeFiles");
UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details");
UIManager.put("FileChooser.fileSizeHeaderText","Size");
UIManager.put("FileChooser.fileDateHeaderText", "DateModified");

//Set icons for the JFileChooser
UIManager.put("FileView.directoryIcon", new ImageIcon(FileSystem.class.getResource("folder.png")));
UIManager.put("FileChooser.homeFolderIcon", new ImageIcon(FileSystem.class.getResource("user-home.png")));
UIManager.put("FileView.computerIcon", new ImageIcon(FileSystem.class.getResource("computer.png")));
UIManager.put("FIleView.floppyDriveIcon", new ImageIcon(FileSystem.class.getResource("media-floppy.png")));
UIManager.put("FileView.hardDriveIcon", new ImageIcon(FileSystem.class.getResource("drive-harddisk.png")));
UIManager.put("FileView.fileIcon", new ImageIcon(FileSystem.class.getResource("file.png")));
UIManager.put("FileChooser.upFolderIcon", new ImageIcon(FileSystem.class.getResource("go.png")));
UIManager.put("FileChooser.newFolderIcon", new ImageIcon(FileSystem.class.getResource("folder-new.png")));
UIManager.put("FileView.fileIcon", new ImageIcon(FileSystem.class.getResource("file.png")));
UIManager.put("FileChooser.listViewIcon", new ImageIcon(FileSystem.class.getResource("listIcon.png")));
UIManager.put("FileChooser.detailsViewIcon", new ImageIcon(FileSystem.class.getResource("details.png")));

//Update UI
SwingUtilities.updateComponentTreeUI(chooser);

1

2021年答案:

其他答案要么不起作用,要么实现起来太有问题了。对我而言,最简单的方法是使用chooser.showOpenDialog(yourJFrame)chooser.showSaveDialog(yourJFrame)

例如:

JFrame frame = new JFrame();
JFileChooser chooser = new JFileChooser(); 
chooser.showOpenDialog(frame);

使用.showOpenDialog()的结果为:

使用 .showSaveDialog() 的结果为:


1
JFileChooser chooser = new JFileChooser(); 
chooser.setDialogType(0);  // gives 'Look In'
chooser.setDialogType(1);  // gives 'Save In'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接