Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4423439

JFileChooser - can't change the language other than the OS language

XMLWordPrintable



      Name: ssT124754 Date: 03/08/2001


      java version "1.3.1-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-beta-b15)
      Java HotSpot(TM) Client VM (build 1.3.1beta-b15, mixed mode)

      I try to change the language of JFileChooser, this don't work.
      If I use JDK 1.3.0 the language was English. Now I use JDK 1.3.1beta
      and the language is German on the same machine with the same user!!!
      The language of the JFileChooser is not selectable (not in 1.3.0 and not in
      1.3.1).
      I use the follow code (it's from JFileChosserDemo.java):

      //Create a file chooser
      final JFileChooser fc = new JFileChooser();

      //Create the open button
      ImageIcon openIcon = new ImageIcon("images/open.gif");
      JButton openButton = new JButton("Open a File...", openIcon);
      openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {


               //FileChooserDemo.this.setLocale(Locale.ENGLISH);
               // OR
               //fc.setLocale(Locale.ENGLISH);
               // OR
               //FileChooserDemo.this.setLocale(Locale.US);
               // OR
               //fc.setLocale(Locale.US);
               // DON'T WORK!


               int returnVal = fc.showOpenDialog(FileChooserDemo.this);

               if (returnVal == JFileChooser.APPROVE_OPTION) {
                   File file = fc.getSelectedFile();
                   //this is where a real application would open the file.
                   log.append("Opening: " + file.getName() + "." + newline);
               } else {
                   log.append("Open command cancelled by user." + newline);
               }
           }
        });

        From where does the JFileChooser get the language German or English?
      How can I change it (I build an international app and so it's necessary)?

      Here are more informations to the language problem with the JFileChooser:
      The installer would have to be internationalised and i18n.jar ist in
      the CLASSPATH.
      The OS of the machine is WinNT 4 supported for German. I determined
      the following: If I modify the language in the OS to English, also the
      JFileChooser
      modifies its language to English and the same is with German.
      This is not so good: In my java application the user can select the
      language when he starts the program, independed from the language of
      the OS, but the JFileChooser use the OS language!

      The following class is my solution for this problem (Language is my own
      translator class, it translate Strings into the user selected language of
      app):


      //Description: a FileChooser with variable language settings
      //------------------------------------------------------------

      package newtron.gui;

      import javax.swing.*;
      import framework.lang.Language;
      import java.awt.Component;

      public class MultiLanguageFileChooser extends JFileChooser {

        static Language lang;

        // constructor, only the super class, not called directly
        public MultiLanguageFileChooser () {
          super();
        }

        // get an instance of the file chooser
        public static MultiLanguageFileChooser getInstance(Language language) {

          lang=language;

          UIManager.put("FileChooser.lookInLabelText",lang.translate("Suchen
      in:"));
       
      UIManager.put("FileChooser.fileNameLabelText",lang.translate("Dateiname:"));
          UIManager.put("FileChooser.filesOfTypeLabelText",lang.translate("Dateien
      des Typs:"));
          UIManager.put("FileChooser.upFolderToolTipText",lang.translate("Eine
      Ebene h÷her"));
       
      UIManager.put("FileChooser.upFolderAccessibleName",lang.translate("H÷her"));
       
      UIManager.put("FileChooser.homeFolderToolTipText",lang.translate("Home"));
       
      UIManager.put("FileChooser.homeFolderAccessibleName",lang.translate("Home"))
      ;
          UIManager.put("FileChooser.newFolderToolTipText",lang.translate("Neuen
      Ordner erstellen"));
       
      UIManager.put("FileChooser.newFolderAccessibleName",lang.translate("Neuer
      Ordner"));
       
      UIManager.put("FileChooser.listViewButtonToolTipText",lang.translate("Liste"
      ));
       
      UIManager.put("FileChooser.listViewButtonAccessibleName",lang.translate("Lis
      te"));
       
      UIManager.put("FileChooser.detailsViewButtonToolTipText",lang.translate("Det
      ails"));
       
      UIManager.put("FileChooser.detailsViewButtonAccessibleName",lang.translate("
      Details"));
       
      UIManager.put("FileChooser.cancelButtonText",lang.translate("Abbrechen"));
       
      UIManager.put("FileChooser.cancelButtonToolTipText",lang.translate("Abbreche
      n der Auswahl"));
          UIManager.put("FileChooser.acceptAllFileFilterText",lang.translate("Alle
      Dateien (*.*)"));

          return new MultiLanguageFileChooser();
        }


        // show the file open dialog
        public int showOpenDialog(Component parent) {
          setDialogTitle(lang.translate("Ùffnen"));
          setApproveButtonToolTipText(lang.translate("AusgewM-^Dhlte Datei ÷ffnen"));
          setDialogType(OPEN_DIALOG);

          return super.showDialog(parent,lang.translate("Ùffnen"));
        }

        // show the file save dialog
        public int showSaveDialog(Component parent) {
          setDialogTitle(lang.translate("Speichern"));
          setApproveButtonToolTipText(lang.translate("AusgewM-^Dhlte Datei
      speichern"));
          setDialogType(SAVE_DIALOG);

          return super.showDialog(parent,lang.translate("Speichern"));
        }
      }


      For better understanding, here are the translations German -> English:

      -------
      Suchen in:
      ----
      Find in:
      ---

      -------
      Dateiname:
      ----
      File name:
      ---

      -------
      Dateien des Typs:
      ----
      File type:
      ---

      -------
      Eine Ebene h÷her
      ----
      Up one level
      ---

      -------
      H÷her
      ----
      Up
      ---

      -------
      Home
      ----
      Home
      ---

      -------
      Neuen Ordner erstellen
      ----
      Create new folder
      ---

      -------
      Neuer Ordner
      ----
      New folder
      ---

      -------
      Liste
      ----
      List
      ---

      -------
      Abbrechen der Auswahl
      ----
      Cancel the selection
      ---

      -------
      AusgewM-^Dhlte Datei ÷ffnen
      ----
      Open selected file
      ---

      -------
      AusgewM-^Dhlte Datei speichern
      ----
      Save selected file
      ---

      -------
      Alle Dateien (*.*)
      ----
      All Files (*.*)
      ---

       
      Best regards from Dresden/Germany
      Maik Wuensche
      (Review ID: 117402)
      ======================================================================

            Unassigned Unassigned
            ssultanasunw Shaheen Sultana (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: