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

JOptionPane.showMessageDialog ignores Locale information but not other methods

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.2
    • globalization

      FULL PRODUCT VERSION :
      java version "1.5.0_07"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Professional, version 2002, service pack 2

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      not relevant

      A DESCRIPTION OF THE PROBLEM :
      JOptionPane.showMessageDialog() method ignores the locale information where as other methods like showConfirmDialog() works fine. Testing for French locale.
      Button on the message dialog appears as OK as in english.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use this code:

      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class JOptionPaneTest extends JFrame implements FocusListener {
        private JTextField textField = new JTextField("Hello");
        public JOptionPaneTest() {
      createComponents();
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      pack();
      setVisible(true);
        }

        private void createComponents() {
      getContentPane().add(textField, BorderLayout.WEST);
      textField.addFocusListener(this);
      getContentPane().add(new JButton("next focus"), BorderLayout.EAST);
        }
        public void focusGained(FocusEvent fe) {}
        public void focusLost(FocusEvent fe) {
      setLocaleToFrench();
      showDialog1(); //Problem
      showDialog1a();
      showDialog2(); //Solution
        }
        private void setLocaleToFrench() {
      JComponent.setDefaultLocale(Locale.FRENCH);
        }
        private void showDialog1() {
      JOptionPane.showMessageDialog(null,"Message", "Title", JOptionPane.ERROR_MESSAGE);
        }
        private void showDialog1a() {
      JOptionPane.showConfirmDialog(null,"Message", "Title", JOptionPane.ERROR_MESSAGE);
        }
        private void showDialog2() {
      String[] options = getOptionsUsingTextMap(Locale.FRENCH);
      JOptionPane.showOptionDialog(null,"Message", "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options , null);
        }
        private String[] getOptionsUsingTextMap(Locale locale) {
      String[] optionsFrench = {"fr__test"};
      String[] optionsEnglish = {"test"};
         if(locale.equals(Locale.FRENCH)) {
      return optionsFrench;
      }else if(locale.equals(Locale.ENGLISH)) {
      return optionsEnglish;
      }
      return null;
        }
        public static void main(String asdp[]) {
      new JOptionPaneTest();
        }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It should show "Oui" in place of "Ok" as the button label
      ACTUAL -
      It is showing "Ok" as the button label

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class JOptionPaneTest extends JFrame implements FocusListener {
        private JTextField textField = new JTextField("Hello");
        public JOptionPaneTest() {
      createComponents();
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      pack();
      setVisible(true);
        }

        private void createComponents() {
      getContentPane().add(textField, BorderLayout.WEST);
      textField.addFocusListener(this);
      getContentPane().add(new JButton("next focus"), BorderLayout.EAST);
        }
        public void focusGained(FocusEvent fe) {}
        public void focusLost(FocusEvent fe) {
      setLocaleToFrench();
      showDialog1(); //Problem
      showDialog1a();
      showDialog2(); //Solution
        }
        private void setLocaleToFrench() {
      JComponent.setDefaultLocale(Locale.FRENCH);
        }
        private void showDialog1() {
      JOptionPane.showMessageDialog(null,"Message", "Title", JOptionPane.ERROR_MESSAGE);
        }
        private void showDialog1a() {
      JOptionPane.showConfirmDialog(null,"Message", "Title", JOptionPane.ERROR_MESSAGE);
        }
        private void showDialog2() {
      String[] options = getOptionsUsingTextMap(Locale.FRENCH);
      JOptionPane.showOptionDialog(null,"Message", "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options , null);
        }
        private String[] getOptionsUsingTextMap(Locale locale) {
      String[] optionsFrench = {"fr__test"};
      String[] optionsEnglish = {"test"};
         if(locale.equals(Locale.FRENCH)) {
      return optionsFrench;
      }else if(locale.equals(Locale.ENGLISH)) {
      return optionsEnglish;
      }
      return null;
        }
        public static void main(String asdp[]) {
      new JOptionPaneTest();
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Mentioned in the code above.
      Commented with "Solution"

            jtusla Jiri Tusla (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: