1

I am having trouble getting the nodes in my Javafx hbox to expand widthwise, when the window it's in is expanded. I have read the Javafx Hbox documentation here.

It says:

"HBox will resize children (if resizable) to their preferred widths"

"If an hbox is resized larger than its preferred width, by default it will keep children to their preferred widths, leaving the extra space unused."

Currently, when I expand my window, I have that extra space that it mentioned above. What I want is for my nodes to take up that extra space. Is there a way to set something like a ratio, for example item one should take up 2/4 of the space, item two 1/4 and item three the remaining 1/4?

If there is not a way to do that, how to I get my nodes to take up the remaining space? This time not caring about the ratio, just getting rid of the extra space and at least some of the nodes expanding regardless of their preferred widths?

Thank you for your help!

user8402764
  • 143
  • 2
  • 14
  • 3
    You probably need to use a `GridPane` with a single row for that functionality. You can use `ColumnConstraints` and set their percentage widths. For the second option you ask about, use `HBox.setHgrow(...)` (and set the control's max width if needed). – James_D Aug 24 '17 at 20:41
  • I used a GridPane and it looks great, thanks again! I spent a long time trying to figure this out. – user8402764 Aug 24 '17 at 22:14

0 Answers0