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

JOptionDialog gives wrong return value

XMLWordPrintable

    • x86
    • windows_xp, windows_vista

      FULL PRODUCT VERSION :
      java 1.6.

      ADDITIONAL OS VERSION INFORMATION :
      Windows Vista

      A DESCRIPTION OF THE PROBLEM :
      If in a Yes/No dialog where Yes is default you shift focus to No by using the Tab key and then use the Return key you still get the Yes result.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      To reproduce:
      1. Run the application
      2. Press "tab" key to switch selection to "No"
      3. Press "enter" shows the selection is Yes.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JOptionPane;
      /*
       * demo.java
       *
       * Created on den 22 augusti 2007, 08:45
       */

      /**
       *
       * @author bosy
       */
      public class demo extends javax.swing.JFrame {
         
          /** Creates new form demo */
          public demo() {
              initComponents();
             
              if(JOptionPane.YES_OPTION==JOptionPane.showConfirmDialog(this,
                      "Do you really want to close this unsaved file ?",
                      "Confirm",
                      JOptionPane.YES_NO_OPTION)){
                  jTextField1.setText("Option YES was selected");
              } else {
                  jTextField1.setText("Option NO was selected");
              }
          }
         
          /** This method is called from within the constructor to
           * initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is
           * always regenerated by the Form Editor.
           */
          // <editor-fold defaultstate="collapsed" desc=" Generated Code
      ">
          private void initComponents() {
              jTextField1 = new javax.swing.JTextField();

              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
              jTextField1.setEditable(false);
              jTextField1.setFont(new java.awt.Font("Tahoma", 1, 12));
              jTextField1.setForeground(new java.awt.Color(255, 51, 102));
              jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);

              javax.swing.GroupLayout layout = new
      javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                  
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addGap(74, 74, 74)
                      .addComponent(jTextField1,
      javax.swing.GroupLayout.PREFERRED_SIZE, 248,
      javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addContainerGap(78, Short.MAX_VALUE))
              );
              layout.setVerticalGroup(
                  
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addGap(90, 90, 90)
                      .addComponent(jTextField1,
      javax.swing.GroupLayout.PREFERRED_SIZE, 31,
      javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addContainerGap(120, Short.MAX_VALUE))
              );
              pack();
          }// </editor-fold>
         
          /**
           * @param args the command line arguments
           */
          public static void main(String args[]) {
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new demo().setVisible(true);
                  }
              });
          }
         
          // Variables declaration - do not modify
          private javax.swing.JTextField jTextField1;
          // End of variables declaration
         
      }
      ---------- END SOURCE ----------


      CUSTOMER SUBMITTED WORKAROUND :
      Press Space or click with the mouse you get the desired No result.

            alexp Alexander Potochkin (Inactive)
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: