2

I have a layout where I have a vertical split pane that divides two components. The component inside the right side of the splitpane I want to grow (it's an image), but the components on the left side of the split pane I want to remain in the exact same place with the divider in the exact same position when the window is enlarged.

I have attempted to wrap the left side AnchorPane in a Vbox and it seemed to work except when the window is resized all of the components in the left side get moved down. This also occurs when I wrap it in an HBox.

I can't think of the best way to fix this. I'm using scene builder and I'm still fairly new to Javafx. Can anyone help?

Thank you!

John
  • 347
  • 1
  • 7
  • 14

1 Answers1

7

Calling setMinWidth and setMaxWidth on the component that must not grow with the same fixed value will prevent the user to change the divider position.

So for example let's say that you want a max size of 100 for your left component, the code could be:

SplitPane pane = new SplitPane();

double leftComponentSize = 100.0;
VBox leftComponent = new VBox();
// Set the min and max width to a fixed size
leftComponent.setMinWidth(leftComponentSize);
leftComponent.setMaxWidth(leftComponentSize);
...
pane.getItems().addAll(leftComponent, rightComponent);
// Initialize the divider positions to allocate the expected size 
// to the left component according to the size of the window
pane.setDividerPositions(leftComponentSize / stage.getScene().getWidth());
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122