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

after doLayout, the splitpane's divider location is changed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P1 P1
    • None
    • 1.4.0
    • client-libs

      Compile and run the following codes, you will find under jdk1.4, the JSplitPane's divider location will change after setRightComponent(), but under jdk1.2, the divider location will keep same.
      It results in JDK's incompatibility.

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

      public class Test {
          JSplitPane pane;
          
          public Test() {
              JFrame frame = new JFrame("Test JSplitPane");
      pane = new JSplitPane();
      frame.getContentPane().add(pane);

      JPanel leftPanel = new JPanel(new FlowLayout());
      JButton bBtn = new JButton("Blue");
      leftPanel.add(bBtn);
      JButton gBtn = new JButton("green");
      leftPanel.add(gBtn);
              pane.setLeftComponent(leftPanel);
      JPanel rightPanel = new JPanel();
      pane.setRightComponent(rightPanel);
      pane.setDividerLocation(120);

      gBtn.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      setRightPanel(Color.green);
      }
      });

      bBtn.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      setRightPanel(Color.blue);
      }
      });

      frame.setSize(500, 500);
      frame.setVisible(true);
          }
          
          void setRightPanel(Color c) {
              JPanel panel = new JPanel();
      panel.setBackground(c);
              pane.setRightComponent(panel);
      System.out.println("divider location: " + pane.getDividerLocation());
          }
          
          public static void main(String[] args) {
              new Test();
          }
      }

            svioletsunw Scott Violet (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: