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

JSplitPane does not resize correctly with frame - depends on speed

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_22"
      Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 64-bit

      A DESCRIPTION OF THE PROBLEM :
      In a Swing GUI, the movement of the divider in a JSplitPane component depends on how fast you resize the container it is in. This leads to the divider getting out of position.

      For example, in a configuration with a left-right JSplitPane with a panel weighting of 0.5, i.e the divider is supposed to stay in the middle: if you grab the right or left side of the frame and drag it slowly, only the right half of the splitpane changes size. If you drag it faster, the divider moves (although not as much as it should to keep the divider centred).

      As a guess, what might be happening is that if you only move 1 pixel before a repaint, it can't resize both sides by half a pixel, so it just resizes one half of the pane. Then you move another pixel and it resizes the same half again. If so, this could be remedied by either having a variable that remembers which half the half pixel was awarded to last time, or (equivalently) store the divider position as a float. If a user changes the position of the divider manually, it will only be by whole pixels.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Load a split pane in a resizable container, e.g. Sun's own demo at http://download.oracle.com/javase/tutorialJWS/uiswing/components/ex6/SplitPaneDividerDemo.jnlp

      2) Grab the right or left side of the window and reduce the size slowly

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The divider stays in the middle of the split pane and both panes reduce in size equally
      ACTUAL -
      The left pane stays the same size and only the right panel changes

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JSplitPane;


      public class NewClass {
          public static void main(String[] args) {
              JSplitPane pane = new JSplitPane();
              JPanel panel1 = new JPanel();
              JPanel panel2 = new JPanel();

              pane.setLeftComponent(panel1);
              pane.setRightComponent(panel2);

              pane.setResizeWeight(0.5);

              JFrame frame = new JFrame();
              frame.add(pane);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(400, 200);
              frame.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: