JSplitPane divider location after resize from JFrame

This problem has vexed me for years. Go to the Sun splitpane tutorial:

http://java.sun.com/docs/books/tutorial/uiswing/components/splitpane.html

and use Webstart to run the first demo:

http://java.sun.com/docs/books/tutorialJWS/uiswing/components/example-1dot4/SplitPaneDemo.jnlp

I do the following:

1. Make the JFrame reasonably big

2. Drag the divider to the right a bit, maybe so the left component has 75% of the space and the right 25%.

3. Resize the JFrame so its width is lesser than the divider's location. When you finish resizing the JFrame, you'll see the divider has a new location. If the code's author had called:

Toolkit.getDefaultToolkit().setDynamicLayout(true);

you could actually see the divider bar moving location toward the left.

4. Now, resize the JFrame back to its size in step one. The divider location stays put, doesn't budge an inch.

I would love for the divider to also resize itself and move back to the location it had in step two. But, for some reason, the default behavior is to not do this. Splitpanes happily reset the divider location when you make the wrapping JFrame smaller but refuse to resize the divider location when you make the wrapping JFrame larger.

Can someone tell me how to solve this problem? I see that they have it working perfectly in Eclipse, the IDE itself. When you make the window smaller and the larger, everything resizes perfectly. SWT trick or something? What is the trick in Swing. Please be explicit as possible.

Thanks

[1607 byte] By [justin_againa] at [2007-10-2 4:31:16]
# 1
splitPane.setResizeWeight(0.5);
camickra at 2007-7-16 0:01:15 > top of Java-index,Desktop,Core GUI APIs...
# 2

That does not work. To verify it, I

1. Downloaded SplitPaneDemo.java

2. Added the line from the previous reply.

All it does is reset the location of the divider bar so you have approximately a 50/50 split for the left and right component. In situations where you start with 90% of the space owned by the left pane and 10% by the right, a resize gets you a 60/40 spilt with this line of code. Not much good.

Anyone?

justin_againa at 2007-7-16 0:01:15 > top of Java-index,Desktop,Core GUI APIs...
# 3

I did this and it seems to work. Keeps the panes percentages in tact within a few percentage points. And I believe I could tweak the following. I add a listener to the divider bar and upon a resize, I reset the resize weight:

BasicSplitPaneDivider divider = ((BasicSplitPaneUI)splitPane.getUI()).getDivider();

divider.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent e) {}

public void mousePressed(MouseEvent e) {}

public void mouseReleased(MouseEvent e) {

double location = ((double)splitPane.getDividerLocation() / (double)splitPane.getWidth());

splitPane.setResizeWeight(location);

}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

});

justin_againa at 2007-7-16 0:01:15 > top of Java-index,Desktop,Core GUI APIs...