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

1.4.1 REGRESSION: Wrong Focus when JSplitPane removed+added to window

XMLWordPrintable

    • x86
    • windows_xp

      Name: jk109818 Date: 01/10/2003


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

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If a JSplitPane containing top & bottom components is added
      to a JFrame, then subsequently the JSplitPane is removed
      and then readded to the JFrame when the window is focused,
      the bottom component of the JSplitPane will always gain
      focus shortly afterwards, irrespective of current focus or
      previous focus state of the JSplitPane.

      This also occurs with similarly layed out components - e.g.
      a JPanel with BorderLayout and components added to NORTH &
      SOUTH.

      This is a regression from 1.4.0 - it is not present in
      1.4.0_03. I did not have earlier versions of 1.4.1 to test
      with. I think this may be linked to bug 4625667, but that
      involved tabbed panes.

      REGRESSION. Last worked in version 1.4

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the attached app.
      2. Click the button marked "Click Me"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected output:

      TOP gained focus.
      Content Pane Rebuilt.

      Actual output:

      TOP gained focus.
      Content Pane Rebuilt.
      BOTTOM gained focus.


      The last line of actual output shows the error occurring.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.beans.PropertyChangeEvent;
      import java.beans.PropertyChangeListener;

      public class FocusBugTest
      {
        public static void main(String[] args)
        {
          final JFrame frame = new JFrame("Focus Problem Test");
          JTextArea textArea1 = new SelfDescribingTextArea("TOP");
          JTextArea textArea2 = new SelfDescribingTextArea("BOTTOM");
          final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
      textArea1, textArea2);
          frame.getContentPane().add(splitPane, BorderLayout.CENTER);

          JButton button = new JButton("Click Me");
          button.addActionListener(
            new ActionListener()
            {
              public void actionPerformed(ActionEvent e)
              {
                frame.getContentPane().remove(splitPane);
                frame.getContentPane().add(splitPane, BorderLayout.CENTER);
                System.out.println("Content Pane Rebuilt.");
              }
            }
          );
          button.setFocusable(false);
          frame.getContentPane().add(button, BorderLayout.SOUTH);
          frame.setSize(400,300);

          DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager
      ().addPropertyChangeListener(
            "permanentFocusOwner",
            new PropertyChangeListener()
            {
              public void propertyChange(PropertyChangeEvent evt)
              {
                final Object newFocusedComponent = evt.getNewValue();
                if (newFocusedComponent != null)
                  System.out.println(newFocusedComponent + " gained focus.");
              }
            }
          );
          frame.show();
        }

        private static class SelfDescribingTextArea extends JTextArea
        {
          public SelfDescribingTextArea(String text)
          {
            super(text);
          }

          public String toString()
          {
            return getText();
          }
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      I have found no means of working round this issue as the
      focus event for the bottom component appears to arrive both
      asynchronously to and after the rebuilding of the component
      hierarchy and any focus requests made during rebuilding.

      Release Regression From : 1.4.0_03
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Review ID: 179216)
      ======================================================================

            ant Anton Tarasov (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: