0

I need to do something like the below in JavaFX:

Layout Example

Can you tell me how can I get only one column to change size (the middle one) in a GridPane layout? These black bordered rectangles are VBoxs. Basically, the width of VBoxs must stay the same and the width of this red marked area should resize. Any ideas or tips?

Nicholas K
  • 15,148
  • 7
  • 31
  • 57
Paxon96
  • 23
  • 3

2 Answers2

0

Use column constraints to set the grow priorities to NEVER/ALWAYS. Assuming the GridPane contains 3 columns and no constraints have been added yet:

ColumnConstraints c1 = new ColumnConstraints();
c1.setHgrow(Priority.NEVER);

ColumnConstraints c2 = new ColumnConstraints();
c2.setHgrow(Priority.ALWAYS);

gridPane.getColumnConstraints().addAll(c1, c2, c1);
fabian
  • 80,457
  • 12
  • 86
  • 114
  • Ok, but how can I 'stick' the right column of GridPane to the right part of o window ? – Paxon96 Oct 02 '18 at 04:56
  • @Paxon96 If the `GridPane` is the root of the scene, this is done automatically. If it's not this depends on the ancestor layouts and is impossible to answer in general. – fabian Oct 02 '18 at 06:41
  • Thank you. I have just used GridPane as a root scene. But I have another issue.Can you tell me, what should I do to set buttons on the right as a auto scalable (height) in a VBox? – Paxon96 Oct 02 '18 at 16:28
  • Set the `maxHeight` of the buttons to positive infinity and set `VBox.vgrow` to `ALWAYS` for all of those buttons. (Assuming you want those buttons to fill the complete height of the scene). – fabian Oct 02 '18 at 18:02
  • Thank you VERY much fabian! :D – Paxon96 Oct 02 '18 at 19:04
-1

Eventhough this is doable, I think it is best to use BorderPane instead.

rizcan
  • 57
  • 1
  • 4