JDK-4148530 : JSplitPane's initial divider location is ignored
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-06-13
  • Updated: 1998-06-16
  • Resolved: 1998-06-16
Related Reports
Duplicate :  
Description

Name: bk70084			Date: 06/12/98


The method JSplitPane.setDividerLocation(double) is ignored if it is used before it's parent
Frame is packed.  

For the following application, if run with

    java SplitPaneBug

it shows the bug.  But if you run it with a parameter, like this:

    java SplitPaneBug x

setDividerLocation() is called just after the Frame.pack() call, and everything works fine.



//-----------------------SplitPaneBug.java--------------------
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
//import java.awt.swing.*;

/**
 * An application that displays two JCheckBoxes. 
 */
public class SplitPaneBug extends JPanel {
    static JFrame frame;
    static String first = new String("Button 1");
    static String second = new String("Button 2");
    JSplitPane variablePane;

    public SplitPaneBug() {
        JScrollPane leftPanel = new JScrollPane(); 
        JScrollPane rightPanel = new JScrollPane(); 
        leftPanel.setPreferredSize(new Dimension(200, 300));
        rightPanel.setPreferredSize(new Dimension(200, 300));

        variablePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 
                true, leftPanel, rightPanel);

        JLabel leftLabel = new JLabel("The Left Pane");                        
        JButton rightButton= new JButton("Put in middle");
        rightButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("Setting divider location to 0.5");
                variablePane.setDividerLocation(0.5);
            }
        });
        variablePane.setLeftComponent(leftLabel);
        variablePane.setRightComponent(rightButton);

        variablePane.setContinuousLayout(true); 
        variablePane.setPreferredSize(new Dimension(400, 300)); 
        variablePane.setDividerSize(3); 
        variablePane.setAlignmentX(LEFT_ALIGNMENT); 

        // I want to set the divider's location
        variablePane.setDividerLocation(0.5);

        System.out.println("Initial divider location: " + 
                variablePane.getDividerLocation());
 
        add(variablePane);
    }

    public void setDiv() {
        variablePane.setDividerLocation(0.5);
    }
           
    public static void main(String args[]) {
        WindowListener l = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        };
 
        SplitPaneBug sp = new SplitPaneBug();
        frame = new JFrame("SplitPaneBug");
        frame.addWindowListener(l);
        frame.getContentPane().add("Center", sp);
        frame.pack();
        if (args.length > 0)
            sp.setDiv();
        frame.setVisible(true);
    }
}


(Review ID: 33013)
======================================================================