I'm using JavaFX-8 to build an application. I'm trying to build an menue. Each menu item is a ToggleButton
all the ToggleButtons
should have the same width. So I used following code snipped:
VBox vbox = new VBox();
ToggleButton toggleButton = new ToggleButton("MyText");
HBox hBox = new HBox();
hBox.getChildren().add(toggleButton);
HBox.setHgrow(toggleButton, Priority.ALWAYS);
toggleButton.setMaxWidth(Double.MAX_VALUE);
[...]
vbox.getChildren().add(hBox,hbox2,hbox3,...);
Result:
The width of each item is now the same, but the text alignment seems to be centred now. I tried to change the alignment to LEFT
by toggleButton.setContentDisplay(ContentDisplay.LEFT)
and toggleButton.setAlignment(Pos.CENTER_LEFT)
but without success. Is there an other way to solve this problem?
Update:
I tried toggleButton.setTextAlignment(TextAlignment.LEFT);
having the same result as before.