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

REGRESSION: Focus does not go to items present on invisible containers

XMLWordPrintable

    • 5.0
    • generic
    • generic

      If focus requested on an item that is placed on a container that is not visible, then focus does not travel to that item. This worked fine in JDK 1.4, but does not work with JDK 1.5. I guess this bug is similar to the bug 5089436 that has been filed.

      This has been broken in JDK 1.5 due to the lines 6549 to 6543 of java.awt.Component. The lines are :

                      if (recursivelyInvisible) {
                          focusLog.finest("FAIL 1.5");
                          return false;
                      }

      Testcase
      ---------
      import java.awt.*;
      import java.awt.event.*;

      public class FocusTest extends Frame implements ActionListener
      {
          Panel panel = new Panel();
          MyButton button1 = new MyButton("Push!");
          MyTextField field1 = new MyTextField(" Field 1");
          MyTextField field2 = new MyTextField(" Field 2");

          FocusTest()
          {
              add(panel);
              addWindowListener(
              new WindowAdapter() {
              public void windowClosing(WindowEvent e) {
              System.exit(0); } } );
              button1.addActionListener(this);
              panel.add(button1);
              panel.add(field1);
              panel.add(field2);
              pack();
          }

          public void actionPerformed(ActionEvent event)
          {
              if ( event.getSource() == button1 )
              {
                  panel.setVisible(false);
                  field2.requestFocus();
                  panel.setVisible(true);
              }
          }

          static public void main(String[] args)
          {
              FocusTest ft = new FocusTest();
              ft.setVisible(true);
          }
      }

      class MyTextField extends TextField implements FocusListener
      {

          MyTextField(String s)
          {
              super(s);
              addFocusListener(this);
          }

          public void requestFocus()
          {
              System.out.println("[MyTextField] requestFocus() from "+
              this.getText());
              super.requestFocus();
          }

          public void focusGained(FocusEvent e)
          {
              System.out.println("[MyTextField] focusGained on " +((MyTextField)(e.getComponent())).getText());
          }

          public void focusLost(FocusEvent e)
          {
              System.out.println("[MyTextField] focusLost on " +((MyTextField)(e.getComponent())).getText());
          }
      }

      class MyButton extends Button implements FocusListener
      {
          MyButton(String s)
          {
              super(s);
              addFocusListener(this);
          }

          public void requestFocus()
          {
              System.out.println("[MyButton] requestFocus() from " + this.getLabel());
              super.requestFocus();
          }

          public void focusGained(FocusEvent e)
          {
              System.out.println("[MyButton] focusGained on " + ((MyButton)(e.getComponent())).getLabel());
          }

          public void focusLost(FocusEvent e)
          {
              System.out.println("[MyButton] focusLost on " + ((MyButton)(e.getComponent())).getLabel());
          }
      }

      Compile and run the testcase. The window that comes up,shows three items - a push button and two text fields.

      Behaviour in JDK1.4
      --------------------
      1. When the push button is pressed,the focus comes to the text field named "Field2"
      2. The following are shown on the console :
      [MyButton] focusGained on Push!
      [MyTextField] requestFocus() from Field 2
      [MyButton] focusLost on Push!
      [MyTextField] focusGained on Field 2

      Behaviour in JDK 1.5
      -------------------------
      1. When the push button is pressed,the focus does not comes to the text field named "Field2"
      2. The following are shown on the console :
      [MyButton] focusGained on Push!
      [MyTextField] requestFocus() from Field 2
      [MyButton] focusLost on Push!

      Release Regression From : 1.4.2_08
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 2005-05-23 16:20:03 GMT

            dmikhalksunw Denis Mikhalkin (Inactive)
            mmma Marvin Ma (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: