r/JavaFX • u/Draaksward_89 • Jan 17 '25
Help Is it possible to define layouts to fill the whole space?
Started working on an app (still brainstorming the details)

With a structure of

But whatever I try, I can't really make a ScrollPane to stretch to the dimensions of the parent AnchorPane(the VBox is one of many attempts to maybe make it right).
I confess that it has been quite a while (6+ years) the last time I read (it took me a while to find this documentation) the details for each JavaFX element and how they function.
I did manage to make it achieve what I wanted through code, adding a listener to Anchor's height property, but the question is - is it my lack of knowledge how to properly work with this type of elements? Or its simply how the things are(maybe I needed to add CSS to make it work)?
UPD: my bad. Wrote ScrollPane instead of the next in line ListView, which is the problem I'm facing.
2
u/walrusone79 Jan 17 '25
Really good info on the basics of javafx can be found here.
https://www.pragmaticcoding.ca/
1
u/Frosty_Garden6755 Jan 17 '25
use fillHeight and fillWidth
1
u/hamsterrage1 Jan 17 '25
If you actually used the AnchorPane like an AnchorPane and anchored the ScrollPane to it on all sides it would fill the AnchorPane.
1
u/SpittingBull Jan 17 '25
You need to actually use the parent AnchorPane and anchor like the VBox to it's 4 sides
2
u/Fancy_Entertainer486 Jan 17 '25
Might not be the best approach, but for small apps and for me personally it always works to wrap whatever layout/control I want to fill a space in a BorderPane since its center property automatically stretches over all available space.