JFileChooser 从菜单按钮更改文本

JFileChooser change text from menu buttons

我想更改 "View Menu" 菜单下的 "List" 按钮文本,但找不到方法。这是文件选择器的图片 window。

JFileChooser dialog window

我试过这些,但没有用:

UIManager.put("FileChooser.listViewButtonText", "Test1");
UIManager.put("FileChooser.listViewButtonName", "Test2");
UIManager.put("FileChooser.listButtonText", "Test3");
UIManager.put("FileChooser.listViewButtonAccessibleName", "Test4");
chooser.updateUI();

有没有人遇到过这个?另外,如果可能的话,我也想更改右键菜单文本。

提前致谢。

这些是必须更改的值:

UIManager.put("FileChooser.detailsViewActionLabelText", "mytext");
UIManager.put("FileChooser.listViewActionLabelText", "myothertext");

您可以在sun.swing.FilePane class 中查看安装值 installDefaults 方法:

protected void installDefaults() {
    Locale l = getFileChooser().getLocale();

    listViewBorder = UIManager.getBorder("FileChooser.listViewBorder");
    listViewBackground = UIManager.getColor("FileChooser.listViewBackground");
    listViewWindowsStyle = UIManager.getBoolean("FileChooser.listViewWindowsStyle");
    readOnly = UIManager.getBoolean("FileChooser.readOnly");

    // TODO: On windows, get the following localized strings from the OS

    viewMenuLabelText = UIManager.getString("FileChooser.viewMenuLabelText", l);
    refreshActionLabelText = UIManager.getString("FileChooser.refreshActionLabelText", l);
    newFolderActionLabelText = UIManager.getString("FileChooser.newFolderActionLabelText", l);

    viewTypeActionNames = new String[VIEWTYPE_COUNT];
    viewTypeActionNames[VIEWTYPE_LIST] = UIManager.getString("FileChooser.listViewActionLabelText", l);
    viewTypeActionNames[VIEWTYPE_DETAILS] = UIManager.getString("FileChooser.detailsViewActionLabelText", l);

    kiloByteString = UIManager.getString("FileChooser.fileSizeKiloBytes", l);
    megaByteString = UIManager.getString("FileChooser.fileSizeMegaBytes", l);
    gigaByteString = UIManager.getString("FileChooser.fileSizeGigaBytes", l);
    fullRowSelection = UIManager.getBoolean("FileView.fullRowSelection");

    renameErrorTitleText = UIManager.getString("FileChooser.renameErrorTitleText", l);
    renameErrorText = UIManager.getString("FileChooser.renameErrorText", l);
    renameErrorFileExistsText = UIManager.getString("FileChooser.renameErrorFileExistsText", l);
}