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

FocusEvent processed twice when requestFocus after JOptionPane.showMessage()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2, 6
    • client-libs
    • x86
    • windows_2000, windows_xp

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 ( build 5.00.2195 ) Service Pack 4

      A DESCRIPTION OF THE PROBLEM :
      When a component lost it focus and at focusLost() you show a JOptionPane.showMessage(), calling requestFocus of the same component that lost it causes a second call to focusLost().

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      When focus goes to text2, shows a message, then when finish to show the message, text1 request focus, and then focusEvent is callend again( no idea by what )


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Do not call two times the focusEvent when forcing the focus on the component that fires focusEvent.
      ACTUAL -
      Calls focusEvent once again after requestFocus() on the same component after displays a modal JDialog

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      public class FocusTest {
          public static void main(String[] args) {
              JFrame frame = new JFrame("Focus test");
              final JTextField field1 = new JTextField("Test1");
              final JTextField field2 = new JTextField("Test2");
              field1.addFocusListener(new FocusAdapter(){
                  public void focusGained(FocusEvent e){}
                  public void focusLost(FocusEvent e){
                      if( !e.isTemporary() ){
                          JOptionPane.showMessageDialog(null, "Focus lost in 1");
                          field1.requestFocus(); //- This makes the focus to be called again
                      }
                  }
              });
              frame.getContentPane().add(field1, BorderLayout.WEST);
              frame.getContentPane().add(field2, BorderLayout.CENTER);
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setBounds(0,0,200,300);
              frame.show();
              
          }
      }
      ---------- END SOURCE ----------

            son Oleg Sukhodolsky (Inactive)
            dav Andrei Dmitriev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: