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

In JOptionPane, selectInitialValue() is not called when first focusing dialog

XMLWordPrintable

    • generic, x86
    • generic, linux



      Name: jk109818 Date: 04/24/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)


      A DESCRIPTION OF THE PROBLEM :
      In the file javax/swing/JOptionPane.java, in the function:

      private JDialog createDialog(Component parentComponent, String title, int style)

      For selecting the initial value, selectInitialValue() is called in windowGainedFocus() in an anonymous inner class extending WindowAdapter. But this inner class is registered using addWindowListener() only, not addWindowFocusListener().

      A possible fix follows. In the source file there is:

      dialog.addWindowListener(new WindowAdapter() {
      ...
      });

      This can be changed to:

      WindowAdapter windowAdapter = new WindowAdapter() {
      ...
      };
      dialog.addWindowListener(windowAdapter);
      dialog.addWindowFocusListener(windowAdapter);



      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      JOptionPane can be subclassed and createDialog overridden as follows:

      class MyOptionPane extends JOptionPane {
          public JDialog createDialog(Component parentComponent, String title) {
              JDialog dialog = super.createDialog (parentComponent, title);
              dialog.addWindowFocusListener(new WindowAdapter() {
                  private boolean gotFocus = false;
                  public void windowGainedFocus(WindowEvent we) {
                      // Once window gets focus, set initial focus
                      if (!gotFocus) {
                          selectInitialValue();
                          gotFocus = true;
                      }
                  }
              });
              return dialog;
          }
      }
      (Review ID: 182728)
      ======================================================================

            Unassigned Unassigned
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: