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

componentResized() not always called with nested JSplitPanes

XMLWordPrintable

    • Fix Understood
    • x86
    • windows_nt

      Name: sv35042 Date: 10/18/2002


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


      FULL OPERATING SYSTEM VERSION :

      Windows NT Version 4.0

      (Service Pack 6)


      A DESCRIPTION OF THE PROBLEM :
      Let a component "comp" be nested inside a JSplitPane "inner"
      with VERTICAL_SPLIT mode. Let "inner" be nested inside a
      JSplitPane "outer" with HORIZONTAL_SPLIT mode. Finally, add
      a component listener to "comp".

      With this setup, componentResized() on the listener is
      called when the divider of "outer" is moved manually.
      However, it is not called when the divider of "outer" is
      moved completely to the left using the triangle at the top
      of the divider.

      The bug doesn't occur when the left component of "outer" is
      a JPanel containing "comp" (this variant is commented out in
      the example source code). It only occurs with the nested
      JSplitPane. Also, a ComponentListener attached to "inner"
      gets called correctly (see example source code).


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a JComponent "comp" (actual class doesn't matter;
      the example source code uses a JScrollPane containing a
      JList, but I've tested others too)

      2. Create a JSplitPane "inner" with VERTICAL_SPLIT mode and
      "comp" as the top component (bottom component doesn't matter)

      3. Create a JSplitPane "outer" with HORIZONTAL_SPLIT mode
      and "inner" as the left component (top component doesn't matter)

      4. Add a component listener to "comp" and monitor the
      componentResized() events

      All of this is done in the provided example source code.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected output of the example source code when the top
      triangle of the horizontal split divider is clicked:

      | inner resized
      | comp resized

      Actual output:

      | inner resized


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;

      import java.util.*;

      public class SplitPaneDemo {
          private Vector listItems;
          private JList list;
          private JSplitPane outer;

          public SplitPaneDemo() {

              // set up a simple list embedded inside a scroll pane
              listItems = new Vector();
              listItems.add("Item 1");
              listItems.add("Item 2");
              list = new JList(listItems);
              list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              list.setSelectedIndex(0);
              JScrollPane comp = new JScrollPane(list);
              
              // --> variant 1: left side of outer JSplitPane is an inner JSplitPane
      containing the list
              JSplitPane inner = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
                                                comp, new JPanel());
              // <--
              
              // --> variant 2: left side of outer JSplitPane is a JPanel containing
      the list
              //JPanel containerPane = new JPanel();
              //containerPane.setLayout(new BorderLayout());
              //containerPane.add(listScrollPane);
              // <--
              
              JPanel rightPanel = new JPanel();
              outer = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                                     inner, rightPanel);
              outer.setOneTouchExpandable(true);
              outer.setDividerLocation(150);

              //Provide minimum sizes for the two components in the split pane
              Dimension minimumSize = new Dimension(100, 50);
              comp.setMinimumSize(minimumSize);
              inner.setMinimumSize(minimumSize);
              rightPanel.setMinimumSize(minimumSize);

              //Provide a preferred size for the split pane
              outer.setPreferredSize(new Dimension(400, 200));
              inner.addComponentListener(new ComponentAdapter() {
               public void componentResized(ComponentEvent e) {
               System.out.println("inner resized");
               }
              });
              comp.addComponentListener(new ComponentAdapter() {
               public void componentResized(ComponentEvent e) {
               System.out.println("comp resized");
               }
              });
          }

          public JSplitPane getSplitPane() {
              return outer;
          }


          public static void main(String s[]) {
              JFrame frame = new JFrame("SplitPaneDemo");

              frame.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {System.exit(0);}
              });

              SplitPaneDemo splitPaneDemo = new SplitPaneDemo();
              frame.getContentPane().add(splitPaneDemo.getSplitPane());
              frame.pack();
              frame.setVisible(true);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Not easy. The problem is that in our real application the
      component in question may appear inside other components
      (not only JSplitPane) and may be moved from one container
      (e.g. JPanel) to another (e.g. JSplitPane) at runtime. It
      would probably still be possible to find a workaround by
      always monitoring the parent component, but it would be
      quite painful.

      Note that we *must* be informed of resizing since we do some
      native drawing in our component. We already use a layout
      manager, but for the native part that doesn't help.
      (Review ID: 158733)
      ======================================================================

            Unassigned Unassigned
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: