I have tried to do this, by adding a component listener to the splitpane,
and manipulating the divider location as the component is resized.
I have not been able to keep the ratio constant. Any ideas?
Thanks.
Amir Kouchekinia
I had the same problem and it took me over 2 weeks to figure this out. ;o)
This seems to work now:
In the PropertyCangeEvent, you must calculate the new percentage if the
SplitPane ist valid. The percentage will only change, when the Divider was
moved. But this works ONLY if continuousLayout is set to true!
public void propertyChange(PropertyChangeEvent p) {
if (this.isValid()) {
spDividerLocation = (double)this.getDividerLocation() /
(double)this.getWidth();
spDividerLocation = dRound(spDividerLocation, 2);
}
}
Then, when the SplitPane is beeing resized, you can update the DividerLocation
with the new value.
public void componentResized (ComponentEvent c) {
this.setDividerLocation(spDividerLocation);
this.doLayout();
}
private double dround(double value, int pre) {
double expo = Math.pow(10, pre);
double newValue = (Math.round(value* pre)) / (double)pre;
return newValue;
}
Pascal