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

3

12

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)

Spartan answered 6/9, 2015 at 18:26 Comment(0)
S
23

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!

Spartan answered 6/9, 2015 at 19:27 Comment(1)
In SceneBuilder you can change the ButtonOrder property of the ButtonBar. If you put U+ at the beginning instead of middle, all your unknown buttons will be left-aligned. But I haven't found a way to do this per-button; and my "left-aligned" buttons seem to end up centered... :(Truncheon
G
1

There is the "Transforms" property in Layout tab of the button on the right side of Scene Builder. Change "Translate X". (The position of the button will change horizontally.) "Translate Y" will change the button's position vertically. You need to calculate the position first.

I just found it.

Geraldine answered 27/10, 2015 at 4:38 Comment(2)
change to what? What the input should be?Carnegie
positive or negative numbers.Geraldine
B
1

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.

Burlburlap answered 24/9, 2018 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.