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)
From the docs I already know how I could achieve this inside the java-source-code:
ButtonBar.setButtonData(newButton, ButtonData.LEFT);
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)
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.
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.
If anyone knows/finds out how to do this directly in SceneBuilder, I would be grateful!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With