JDK-4276222 : JSplitPane setDividerLocation still not working correctly (NT)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.2
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-09-28
  • Updated: 1999-10-04
  • Resolved: 1999-10-04
Related Reports
Relates :  
Description

Name: rlT66838			Date: 09/28/99


This was originally reported in bug #4101306, but that
bug is closed so I am re-reporting. 
The SplitPane's setDividerLocation does not work correctly
unless the item is visible. Here's example code:


import java.awt.*;
import java.awt.event.*;

public class TestApp extends JFrame implements ActionListener
{
JLabel label = new JLabel("Enter divider location [%]:");
JTextField text = new JTextField("20");
JButton preBut = new JButton("set and show");
JButton postBut = new JButton("show and set");

public TestApp() {
super("Testcase (4101306)");

preBut.addActionListener(this);
postBut.addActionListener(this);

this.getContentPane().setLayout(new GridLayout(4, 1));
this.getContentPane().add(label);
this.getContentPane().add(text);
this.getContentPane().add(preBut);
this.getContentPane().add(postBut);

this.addWindowListener(new WindowHandler());
this.setSize(200, 125);
this.setVisible(true);
}

public void actionPerformed(ActionEvent ev) {
double value = Double.valueOf(text.getText()).doubleValue();
if ((value < 0.0) || (value > 100.0)) {
System.err.println("Given value not between " +
"0 and 100");
return;
}
value /= 100.0;

if (ev.getSource() == preBut) {
new PreShownSplitter(value);
}
else if (ev.getSource() == postBut) {
new PostShownSplitter(value);
}
}

static public void main(String args[]) {
new TestApp();
}
}

class PreShownSplitter extends JFrame
{
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
true,
new JPanel(),
new JPanel());

public PreShownSplitter(double location) {
super("Set divider then show");

split.setDividerLocation(location);

this.getContentPane().add(split);

this.addWindowListener(new WindowHandler());
this.setSize(200, 200);
this.setLocation(250, 1);
this.setVisible(true);
}
}

class PostShownSplitter extends JFrame
{
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
true,
new JPanel(),
new JPanel());

public PostShownSplitter(double location) {
super("Show then set divider");

this.getContentPane().add(split);

this.addWindowListener(new WindowHandler());
this.setSize(200, 200);
this.setLocation(1, 200);
this.setVisible(true);

split.setDividerLocation(location);
}
}

class WindowHandler extends WindowAdapter
{
public void windowClosing(WindowEvent ev) {
if (ev.getWindow() instanceof TestApp) {
System.exit(0);
}
else {
ev.getWindow().dispose();
}
}
}
(Review ID: 48638) 
======================================================================

Comments
EVALUATION From the javadoc for setDividerLocation(double): * <p>This method is implemented in terms of setDividerLocation(int). * This method immediately changes the size of the receiver based on * its current size. If the receiver is not correctly realized and on * screen, this method will have no effect (new dividier location will * become (current size * proportionalLocation) which is 0). So, as you can see the JSplitPane MUST be visible invoking this method otherwise it will not have the desired effect. scott.violet@eng 1999-10-04
04-10-1999