Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX: Align Buttons inside ButtonBar (using SceneBuilder or fxml)

I have a JavaFX ButtonBar with two Buttons (created via SceneBuilder).

I want one of the buttons to be left-aligned and the other right-aligned. (see screenshot)

enter image description here

From the docs I already know how I could achieve this inside the java-source-code:

ButtonBar.setButtonData(newButton, ButtonData.LEFT);

BUT

I want to know how to achieve this WITHOUT having to write this inside my java-files but
how I can achieve this using just SceneBuilder or the corresponding fxml file.

My .fxml file currently looks like this:

<ButtonBar>
  <buttons>
    <Button text="New" />
    <Button text="Save" />
  </buttons>
</ButtonBar>

* I'm on Windows
** This answer is not what I want, because he is using a ToolBar, but I want to know how to do this with a ButtonBar (and his approach does not work for the ButtonBar)

like image 302
drkthng Avatar asked Sep 06 '15 18:09

drkthng


2 Answers

enter image description here

Via the Inspector, usually on the right side in NetBeans, you will find the tab "Layout". Open it and scroll to the section "Transform".

The option "Translate X" is for adjusting the buttons in the buttonbar at the x-axis.

like image 126
Kevin O. Avatar answered Sep 21 '22 09:09

Kevin O.


After some Trial and Error I found at least a way to do it directly via the .fxml-file:

You can assign the Button elements with ButtonBar.buttonData attributes and then assign a value to them.

<ButtonBar>
  <buttons>
    <Button text="New" ButtonBar.buttonData="LEFT" />
    <Button text="Save" ButtonBar.buttonData="RIGHT" />
  </buttons>
</ButtonBar>

The docs for the ButtonBar.ButtonData enum are pretty straighforward. So I found the solution to my problem with the "LEFT" and "RIGHT" enum values.

STILL

If anyone knows/finds out how to do this directly in SceneBuilder, I would be grateful!

like image 41
drkthng Avatar answered Sep 20 '22 09:09

drkthng