0
votes

I'm a bit new to Javafx and have only ever done simple projects with it. I'm currently working on a more complex project and I'm stumbled into an issue with ScrollPanes. I'm struggling to find out how to make the ScrollPane resize in height whenever I resize the application. Here is my structure:

Structure

The Pane indicated by the orange arrow works fine, I can add constraints as shown here:

Constraints

However I do not have the constraint options on the ScrollPane or the AnchorPane inside of the ScrollPane, which results in this upon resizing of the application:

enter image description here

If I remove the parent Pane and just put the ScrollPane in it's place, I can add the constraints, however if I did that I would not be able to properly design the application as I have it now. In short, I'm just curious if there's an alternate method I can use or if I'm just using bad practice, in which case any advice is appreciated.

1
AnchorPane is almost never a good choice, as it encourages the equivalent of “absolute layouts.” The Pane class definitely should not be used. If you want a single component to fill all available space, make it the center of a BorderPane. I recommend reading (at least) the class level documentation of BorderPane, GridPane, FlowPane, TilePane, StackPane, HBox, and VBox. Remember that nesting layouts is normal and expected. - VGR

1 Answers

0
votes

Pane simply resizes the children to the preferred size and keeps the position. This means no resizing is applied. Also it does not offer any further layout constraints.

You could simply replace the parent pane with a AnchorPane and the anchors become available again.

However a AnchorPane(base) containing that many Panes, probably all with different AnchorPane constraints, indicates that the scene should probably be restructured a bit. E.g. a GridPane, VBox, HBox or a combination of those could help you achieve the desired result in a simpler way.

See Using Built-in Layout Panes for a description of the available layouts and example uses.