javaswingjfilechooseruimanager

JFileChooser change text from menu buttons


I want to change the "List" button text under the "View Menu" menu, but i can't find the way to do it. Here is a picture of the file chooser window.

JFileChooser dialog window

I tried these, but didn't work:

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

Has anyone encoutered this? Also, if possible i would like to change right click menu texts as well.

Thank you in advance.


Solution

  • These are the values that must be changed:

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

    preview

    You can see the installed values in sun.swing.FilePane class in installDefaults method:

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