int previousWidth = getWidth();
int previousHeight = getHeight();
super.setSize(width, height);
SplitPane splitPane = (SplitPane)getComponent();
Orientation orientation = splitPane.getOrientation();
if (splitPane.getResizeMode() == SplitPane.ResizeMode.PRIMARY_REGION
&& ((previousWidth != width && orientation == Orientation.HORIZONTAL)
|| (previousHeight != height && orientation == Orientation.VERTICAL))) {
SplitPane.Region primaryRegion = splitPane.getPrimaryRegion();
float splitRatio = splitPane.getSplitRatio();
if (orientation == Orientation.HORIZONTAL) {
int splitLocation = (int)(splitRatio * previousWidth);
if (primaryRegion == SplitPane.Region.BOTTOM_RIGHT) {
// Move the split location to maintain size on the right
splitLocation += (width - previousWidth);
}
splitRatio = (float)limitSplitLocation(splitLocation) / width;
} else {
int splitLocation = (int)(splitRatio * previousHeight);
if (primaryRegion == SplitPane.Region.BOTTOM_RIGHT) {
// Move the split location to maintain size on the bottom
splitLocation += (height - previousHeight);
}
splitRatio = (float)limitSplitLocation(splitLocation) / height;
}
splitPane.setSplitRatio(splitRatio);
}
}