Localizing a JFileChooser

Change the default values using the UIManager class. The default map contains a number
of key-values that are used by the FileChooser component. The following example shows you
how to change the open-file JFileChooser component to contain some dutch values.

Main.java:

import javax.swing.filechooser.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
 
public class Main extends JFrame {
   public Main() {
      super("JFileChooser Localization Demonstration");
 
      UIManager.put("FileChooser.filesOfTypeLabelText", "Bestanden van type:");
      UIManager.put("FileChooser.filesOfTypeLabelMnemonic", new Integer('t'));
      UIManager.put("FileChooser.fileNameLabelText", "Bestandsnaam:");
      UIManager.put("FileChooser.fileNameLabelMnemonic", new Integer('n'));
      UIManager.put("FileChooser.lookInLabelText", "Kijk in:");
      UIManager.put("FileChooser.lookInLabelMnemonic", new Integer('i'));
      UIManager.put("FileChooser.openButtonText", "Openen");
      UIManager.put("FileChooser.openButtonMnemonic", new Integer('o'));
      UIManager.put("FileChooser.cancelButtonText", "Annuleren");
      UIManager.put("FileChooser.cancelButtonMnemonic", new Integer('a'));
   
      getContentPane().setLayout(new FlowLayout()); 
      JFileChooser fileChooser = new JFileChooser(); 
 
      getContentPane().add(fileChooser); 
  
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }
      });
   }
 
   public static void main(String[] args) {
      Main main = new Main();
      main.pack();
      main.setVisible(true);
   }
}

Using the UIManager.put call, you can change the values of the following default keys:

FileChooser.acceptAllFileFilterText
FileChooser.cancelButtonMnemonic
FileChooser.cancelButtonText
FileChooser.cancelButtonToolTipText
FileChooser.detailsViewButtonAccessibleName
FileChooser.detailsViewButtonToolTipText
FileChooser.detailsViewIcon
FileChooser.directoryDescriptionText
FileChooser.fileDescriptionText
FileChooser.fileNameLabelMnemonic
FileChooser.fileNameLabelText
FileChooser.filesOfTypeLabelMnemonic
FileChooser.filesOfTypeLabelText
FileChooser.helpButtonMnemonic
FileChooser.helpButtonText
FileChooser.helpButtonToolTipText
FileChooser.homeFolderAccessibleName
FileChooser.homeFolderIcon
FileChooser.homeFolderToolTipText
FileChooser.listViewButtonAccessibleName
FileChooser.listViewButtonToolTipText
FileChooser.listViewIcon
FileChooser.lookInLabelMnemonic
FileChooser.lookInLabelText
FileChooser.newFolderAccessibleNam
FileChooser.newFolderErrorSeparator
FileChooser.newFolderErrorText
FileChooser.newFolderIcon
FileChooser.newFolderToolTipText
FileChooser.openButtonMnemonic
FileChooser.openButtonText
FileChooser.openButtonToolTipText
FileChooser.saveButtonMnemonic
FileChooser.saveButtonText
FileChooser.saveButtonToolTipText
FileChooser.upFolderAccessibleName
FileChooser.upFolderIcon
FileChooser.upFolderToolTipText
FileChooser.updateButtonMnemonic
FileChooser.updateButtonText
FileChooser.updateButtonToolTipText