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

JOptionPane should return null when cancel is clicked

XMLWordPrintable

    • b03
    • x86
    • windows_xp
    • Verified

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

      ADDITIONAL OS VERSION INFORMATION :
      ver winxp home svc. pack 2

      A DESCRIPTION OF THE PROBLEM :
      When an item in joptionpane is doubleclicked, then [cancel] is clicked the value returned is NOT null, as it should be. Instead it is as if the user had selected the [ok] button because the returned value is not null.

      Works fine when item is clicked only once!


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. double click item from joptionpane (list)
      2. click cancel button or [x] from title bar.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Joptiondialog should return a null value when cancel button is clicked
      ACTUAL -
      joptionpane returns the item that was double clicked EVEN THOUGH cancel button was pressed after double clicking item

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.lang.reflect.Array;

      import javax.swing.JFrame;
      import javax.swing.JOptionPane;

      class Test extends JFrame {

          public void showTestOptionDialog() {

              Object[] selectedItems = new Object[40];
              for (int i = 0; i < 39; i++) {
                  selectedItems[i] = ("item :" + i);
              }
              String answer = (String) JOptionPane.showInputDialog(this,
                      "Double click on selected item then click cancel",
                      "Test Option Dialog", JOptionPane.WARNING_MESSAGE, null,
                      selectedItems, selectedItems[0]);

              // if cancel clicked
              if (answer == null) {
                  JOptionPane.showMessageDialog(null,
                          "Cancel clicked (answer should be null!), answer = " + answer,
                          null,
                          JOptionPane.INFORMATION_MESSAGE);
              
                  
                  System.out.println("Cancel clicked, answer = " + answer);
                 // selectedItems = null;
                  return;
                  // else if OK clicked
              } else if (answer != null) {
                  JOptionPane.showMessageDialog(null,
                          "OK clicked, answer = " + answer,
                          null,
                          JOptionPane.INFORMATION_MESSAGE);
                  
                  
                  
                  System.out.println("OK clicked, answer =" + answer);
              }
          }

          public static void main(String[] args) {
              Test test = new Test();
              test.showTestOptionDialog();
          }
      }

      ---------- END SOURCE ----------

            mlapshin Mikhail Lapshin (Inactive)
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: