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

Focus issue with JFrame and JButton

    • b03
    • x86
    • windows, windows_xp

        while running the below testcase focus and functionality are lost after
        moving focus out of IE and back to the applet.

        Steps to reproduce.

        Click serveral(4-6) times on the Non navigable Button
        move the cursor out of IE and click on another window.
        In my test I used a command prompt
        move cursor back into the applet and click on the Focuesed Button
        and then on the Non navigable Button.
        Focus should be lost on the the Focused Button
        and functionality lost on both buttons.
        I've run it a few times and sometimes you may need to repeat the above
        a couple of times.

        (edited and replaced in this description the correct test case)
        NewMDIDemo.java

        import java.awt.BorderLayout;
        import java.awt.Component;
        import java.awt.Frame;
        import java.awt.Window;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.awt.event.FocusAdapter;
        import java.awt.event.FocusEvent;

        import javax.swing.JApplet;
        import javax.swing.JButton;
        import javax.swing.JPanel;

        import sun.awt.SunToolkit;


        public class NewMDIDemo extends JApplet
        {
          public void init()
          {
            JPanel comp = new JPanel();
            _createDummy(comp);
            getContentPane().add("Center", comp);

            Component parent = comp.getParent();
            while ( parent != null && !(parent instanceof Frame) )
            {
                parent = parent.getParent();
            }
            SunToolkit.setLWRequestStatus((Window)parent, true);
          }

          private void _createDummy(JPanel rootPanel)
          {
            rootPanel.setLayout(new BorderLayout());
            final JButton btn1 = new JButton("Non navigable Button");
            final JButton btn2 = new JButton("Focused Button");
            rootPanel.add(btn1, BorderLayout.NORTH);
            rootPanel.add(btn2);

            btn1.addFocusListener(new FocusAdapter()
            {
              public void focusGained(FocusEvent event)
              {
                try
                {
                  synchronized (this)
                  {
                    wait(3000);
                  }
                }
                catch (Exception ex)
                {
                  System.out.println(ex.toString());
                }

                btn2.requestFocus();
              }
            });

            btn2.addFocusListener(new FocusAdapter()
            {
              public void focusGained(FocusEvent event)
              {
                System.out.println("btn2 focusGained");
              }
            });
          }
        }
        revised/corrected test

              nikgor Nikolay Gorshkov
              msusko Mark Susko (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: