How to right align a button in Java FX toolbar

Japheth Ongeri - inkalimeva picture Japheth Ongeri - inkalimeva · Jul 22, 2014 · Viewed 22.9k times · Source

I am building a UI using Java FX scene builder and I want a button in a toolbar to float towards the right side of the toolbar. I have tried changing the node orientation of the parent(toolbar) and also the button but both seem to be ignored.

Answer

jewelsea picture jewelsea · Jul 23, 2014

Add a pane with no content which always grows to fit available space between the left aligned tools in the bar and right aligned ones.

tool

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<ToolBar prefHeight="40.0" prefWidth="318.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
   <Button text="Apples" />
   <Button text="Oranges" />
   <Pane HBox.hgrow="ALWAYS" />
   <Button text="Help" />
</ToolBar>