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

JSplitPane current and last divider positions incorrect when realized

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.1
    • 1.4.0
    • client-libs
    • hopper
    • x86
    • windows_2000
    • Verified



      Name: jl125535 Date: 12/18/2001


      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

      JSplitPane component with a left and right component has its current divider
      position incorrectly set to -1 once it is fully realized. For JDK 1.3.1, its
      value is set to 0. The current position of the divider should be the current
      position of the divider once layout management is complete. If the divider is
      moved one pixel, the current divider position is updated to the correct value
      but the last divider position is then set to -1 (i.e. the last value of the
      current divider position). If the divider is moved again, everything is OK.

      Below is an example of the problem... bring up the example and click the
      trigger button. It will show that the current divider position is incorrect
      (says that it is -1 but it should not be). Slide the divide one pixel and
      click the trigger button again. It will show that the current divider position
      is now current but the last divider position is set to 0.


      import javax.swing.event.*;
      import javax.swing.*;
      import java.awt.event.*;
      import java.awt.*;

      public class SplitPaneTest
      {
          public static void main(String[] args)
          {
              try {
                  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              }
              catch (Exception e) {
                  e.printStackTrace();
              }
              
              JFrame frame = new JFrame("Split Pane Test");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setResizable(false);
              frame.getContentPane().setLayout(new BorderLayout());

              JButton leftButton = new JButton("Left Button");
              JButton rightButton = new JButton("Right Button");
              
              final JSplitPane splitPane =
                  new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                                 true,
                                 leftButton,
                                 rightButton);
              frame.getContentPane().add(splitPane, BorderLayout.CENTER);
              
              JToggleButton triggerButton = new JToggleButton("Trigger");
              triggerButton.setPreferredSize(
                  new Dimension(800, triggerButton.getPreferredSize().height));
              triggerButton.setMinimumSize(
                  new Dimension(800, triggerButton.getPreferredSize().height));
              triggerButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent event)
                  {
                      System.out.println("Current=" + splitPane.getDividerLocation()
                                         + ",Last="
                                         + splitPane.getLastDividerLocation());
                  }
              });
              frame.getContentPane().add(triggerButton, BorderLayout.SOUTH);
              
              frame.pack();
              frame.setVisible(true);
          }
      }

      ADDITIONAL COMMENTS FROM ANALYZER

      Windows 2000 with JDK 1.3.1 or JDK 1.4 beta 3 produces output that
      looks like the following (Solaris 8 with JDK 1.3.1 behaves similarly):

      Current=-1,Last=0
      Current=92,Last=91
      Current=90,Last=91
      Current=90,Last=91
      Current=92,Last=91
      Current=116,Last=115

      Notice that
        getLastDividerLocation() = getDividerLocation() + delta,
        where delta is a number whose absolute value is <= 2

      regardless of where the user moves the splitter.


      Solaris 8 with JDK 1.4 beta 3 produces output that looks like
      the following:

      Current=-1,Last=0
      Current=-1,Last=0
      Current=87,Last=-1
      Current=87,Last=-1
      Current=92,Last=87
      Current=83,Last=92
      Current=83,Last=92
      Current=83,Last=120

      The mismatch between last values and preceding current values
      is unexpected

      In both cases, having a divider location of -1 seems odd.
      (Review ID: 136972)
      ======================================================================

            apikalev Andrey Pikalev
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: