HBox, with the additional functionality
for operating system specific button placement. In other words, any Node may
be annotated (via the ButtonBar#setButtonData(Node, ButtonData)
method, placed inside a ButtonBar (via the getButtons() list), and will
then be positioned relative to all other nodes in the button list based on their
annotations, as well as the overarching
button order specified for the ButtonBar.
By default all buttons are uniformly sized in a ButtonBar, meaning that all
buttons take the width of the widest button. It is possible to opt-out of this
on a per-button basis, but calling the setButtonUniformSize(Node, boolean) method with
a boolean value of false.
If a button is excluded from uniform sizing, it is both excluded from being resized away from its preferred size, and also excluded from the measuring process, so its size will not influence the maximum size calculated for all buttons in the ButtonBar.
Because a ButtonBar comes with built-in support for Windows, Mac OS and Linux, there are three screenshots shown below, with the same buttons laid out on each of the three operating systems.
Windows:



Instantiating and using the ButtonBar is simple, simply do the following:
// Create the ButtonBar instance
ButtonBar buttonBar = new ButtonBar();
// Create the buttons to go into the ButtonBar
Button yesButton = new Button("Yes");
ButtonBar.setButtonData(yesButton, ButtonData.YES);
Button noButton = new Button("No");
ButtonBar.setButtonData(noButton, ButtonData.NO);
// Add buttons to the ButtonBar
buttonBar.getButtons().addAll(yesButton, noButton);
The code sample above will position the Yes and No buttons relative to the users operating system. This means that on Windows and Linux the Yes button will come before the No button, whereas on Mac OS it'll be No and then Yes.
In most cases the OS-specific layout is the best choice, but in cases
where you want a custom layout, this is achieved be modifying the
button order property. These are cryptic-looking
strings that are shorthand representations for the button order. The built-in
orders for Windows, Mac OS and Linux are:
| Operating System | Button Order |
|---|---|
| Windows | L_E+U+FBXI_YNOCAH_R |
| Mac OS | L_HE+U+FBIX_NCYOA_R |
| Linux | L_HE+UNYACBXIO_R |
You should refer to the ButtonData enumeration for a description of
what each of these characters mean. However, if your ButtonBar only consisted
of ButtonData#YES and ButtonData#NO buttons, you always
wanted the yes buttons before the no buttons, and you wanted the buttons to
be right-aligned, you could do the following:
// Create the ButtonBar instance
ButtonBar buttonBar = new ButtonBar();
// Set the custom button order
buttonBar.setButtonOrder("+YN");
ButtonData
| Modifier and Type | Class and Description |
|---|---|
| public static enum | ButtonBar.
An enumeration of all available button data annotations. |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | BUTTON_ORDER_LINUX
The default button ordering on Linux (specifically, GNOME). |
| public static final String | BUTTON_ORDER_MAC_OS
The default button ordering on Mac OS. |
| public static final String | BUTTON_ORDER_NONE
A button ordering string that specifies there is no button ordering. |
| public static final String | BUTTON_ORDER_WINDOWS
The default button ordering on Windows. |
| private final DoubleProperty | |
| private final StringProperty | |
| private ObservableList |
| Access | Constructor and Description |
|---|---|
| public | ButtonBar()
Creates a default ButtonBar instance using the default properties for the users operating system. |
| public | ButtonBar(final String
The button order to use in this button bar instance. buttonOrder)Creates a ButtonBar with the given button order (refer to
|
| Modifier and Type | Method and Description |
|---|---|
| public final DoubleProperty | Returns: the minimum width propertySpecifies the minimum width of all buttons placed in this button bar. |
| public final StringProperty | Returns: the button order propertyThe order for the typical buttons in a standard button bar. |
| protected Skin | createDefaultSkin()
Overrides javafx. Create a new instance of the default skin for this control. |
| public static ButtonBar. | Returns: the previously set ButtonData property on the given buttonThe button to return the previously set ButtonData for. button)Returns the previously set ButtonData property on the given button. |
| public final double | Returns: the minimum width valueReturns the minimum width of all buttons placed in this button bar. |
| public final String | |
| public final ObservableList | Returns: A list containing all buttons currently in the button bar, and allowing for further buttons to be added or removed.Placing buttons inside this ObservableList will instruct the ButtonBar
to position them relative to each other based on their specified
|
| protected Boolean | getInitialFocusTraversable()
Overrides javafx. Returns the initial focus traversable state of this control, for use by the JavaFX CSS engine to correctly set its initial value. |
| public static boolean | Returns: true if button is part of the uniform sizing calculationsthe button button)Returns whether the given node is part of the uniform sizing calculations or not. |
| public static void | setButtonData(Node
The button to annotate with the given button, ButtonBar.ButtonData value.The ButtonData to designate the button as. buttonDataSets the given ButtonData on the given button. |
| public final void | setButtonMinWidth(double
the minimum width value value)Sets the minimum width of all buttons placed in this button bar. |
| public final void | setButtonOrder(String
The currently set button order, which by default will
be the OS-specific button order. buttonOrder)Sets the |
| public static void | setButtonUniformSize(Node
The button to include / exclude from uniform sizing. button, boolean Boolean true to force uniform sizing on the button,
false to exclude the button from uniform sizing. uniformSize)By default all buttons are uniformly sized in a ButtonBar, meaning that all buttons take the width of the widest button. |
| BUTTON_ORDER_LINUX | back to summary |
|---|---|
| public static final String BUTTON_ORDER_LINUX The default button ordering on Linux (specifically, GNOME). | |
| BUTTON_ORDER_MAC_OS | back to summary |
|---|---|
| public static final String BUTTON_ORDER_MAC_OS The default button ordering on Mac OS. | |
| BUTTON_ORDER_NONE | back to summary |
|---|---|
| public static final String BUTTON_ORDER_NONE A button ordering string that specifies there is no button ordering. In
other words, buttons will be placed in the order that exist in the
| |
| BUTTON_ORDER_WINDOWS | back to summary |
|---|---|
| public static final String BUTTON_ORDER_WINDOWS The default button ordering on Windows. | |
| buttonMinWidthProperty | back to summary |
|---|---|
| private final DoubleProperty buttonMinWidthProperty | |
| buttonOrderProperty | back to summary |
|---|---|
| private final StringProperty buttonOrderProperty | |
| buttons | back to summary |
|---|---|
| private ObservableList<Node> buttons | |
| ButtonBar | back to summary |
|---|---|
| public ButtonBar() Creates a default ButtonBar instance using the default properties for the users operating system. | |
| ButtonBar | back to summary |
|---|---|
| public ButtonBar(final String buttonOrder) Creates a ButtonBar with the given button order (refer to
| |
| buttonMinWidthProperty | back to summary |
|---|---|
| public final DoubleProperty buttonMinWidthProperty() Specifies the minimum width of all buttons placed in this button bar.
| |
| buttonOrderProperty | back to summary |
|---|---|
| public final StringProperty buttonOrderProperty() The order for the typical buttons in a standard button bar. It is
one letter per
| |
| createDefaultSkin | back to summary |
|---|---|
| protected Skin Overrides javafx. Doc from javafx. Create a new instance of the default skin for this control. This is called to create a skin for the control if
no skin is provided via CSS
| |
| getButtonData | back to summary |
|---|---|
| public static ButtonBar. Returns the previously set ButtonData property on the given button. If this was never set, this method will return null.
| |
| getButtonMinWidth | back to summary |
|---|---|
| public final double getButtonMinWidth() Returns the minimum width of all buttons placed in this button bar.
| |
| getButtonOrder | back to summary |
|---|---|
| public final String getButtonOrder() Returns the current
| |
| getButtons | back to summary |
|---|---|
| public final ObservableList Placing buttons inside this ObservableList will instruct the ButtonBar
to position them relative to each other based on their specified
| |
| getInitialFocusTraversable | back to summary |
|---|---|
| protected Boolean getInitialFocusTraversable() Overrides javafx. Returns the initial focus traversable state of this control, for use by the JavaFX CSS engine to correctly set its initial value. This method is overridden as by default UI controls have focus traversable set to true, but that is not appropriate for this control.
| |
| isButtonUniformSize | back to summary |
|---|---|
| public static boolean isButtonUniformSize(Node button) Returns whether the given node is part of the uniform sizing calculations
or not. By default all nodes that have not opted out (via
| |
| setButtonData | back to summary |
|---|---|
| public static void setButtonData(Node button, ButtonBar. Sets the given ButtonData on the given button. If this button is
subsequently placed in a
| |
| setButtonMinWidth | back to summary |
|---|---|
| public final void setButtonMinWidth(double value) Sets the minimum width of all buttons placed in this button bar.
| |
| setButtonOrder | back to summary |
|---|---|
| public final void setButtonOrder(String buttonOrder) Sets the
| |
| setButtonUniformSize | back to summary |
|---|---|
| public static void setButtonUniformSize(Node button, boolean uniformSize) By default all buttons are uniformly sized in a ButtonBar, meaning that all buttons take the width of the widest button. It is possible to opt-out of this on a per-button basis, but calling the setButtonUniformSize method with a boolean value of false. If a button is excluded from uniform sizing, it is both excluded from being resized away from its preferred size, and also excluded from the measuring process, so its size will not influence the maximum size calculated for all buttons in the ButtonBar.
| |
ButtonBar with one of these annotations, the
buttons will be appropriately positioned relative to all other buttons in
the ButtonBar.
For details on the button order code for each ButtonData, refer to the javadoc comment.
| Modifier and Type | Field and Description |
|---|---|
| public static final ButtonBar. | APPLY
A tag for the "apply" button. |
| public static final ButtonBar. | BACK_PREVIOUS
A tag for the "back" or "previous" button. |
| public static final ButtonBar. | BIG_GAP
A glue push gap that will take as much space as it can and at least an "unrelated" gap. |
| public static final ButtonBar. | CANCEL_CLOSE
A tag for the "cancel" or "close" button. |
| private final boolean | |
| private final boolean | |
| public static final ButtonBar. | FINISH
A tag for the "finish". |
| public static final ButtonBar. | HELP
A tag for the "help" button that normally is supposed to be on the right. |
| public static final ButtonBar. | HELP_2
A tag for the "help2" button that normally is supposed to be on the left. |
| public static final ButtonBar. | LEFT
Buttons with this style tag will statically end up on the left end of the bar. |
| public static final ButtonBar. | NEXT_FORWARD
A tag for the "next" or "forward" button. |
| public static final ButtonBar. | NO
A tag for the "no" button. |
| public static final ButtonBar. | OK_DONE
A tag for the "ok" or "done" button. |
| public static final ButtonBar. | OTHER
All Uncategorized, Other, or "Unknown" buttons. |
| public static final ButtonBar. | RIGHT
Buttons with this style tag will statically end up on the right end of the bar. |
| public static final ButtonBar. | SMALL_GAP
An "unrelated" gap. |
| private final String | |
| public static final ButtonBar. | YES
A tag for the "yes" button. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: the single character code used to represent the ButtonData annotationReturns the single character code used to represent the ButtonData
annotation in the |
| public final boolean | Returns: true if this is a 'cancel' buttonIndicates whether buttons created from the ButtonData enumeration should be the 'cancel' button in the user interface. |
| public final boolean | Returns: true if this is a 'default' buttonIndicates whether buttons created from the ButtonData enumeration should be the 'default' button in the user interface. |
| public static ButtonBar. | |
| public static ButtonBar. |
| APPLY | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "apply" button. Button order code: A | |
| BACK_PREVIOUS | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "back" or "previous" button. Button order code: B | |
| BIG_GAP | back to summary |
|---|---|
| public static final ButtonBar. A glue push gap that will take as much space as it can and at least an "unrelated" gap. (Platform dependent) Button order code: + | |
| CANCEL_CLOSE | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "cancel" or "close" button. Is cancel button: True Button order code: C | |
| cancelButton | back to summary |
|---|---|
| private final boolean cancelButton | |
| defaultButton | back to summary |
|---|---|
| private final boolean defaultButton | |
| FINISH | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "finish". Is default button: True Button order code: I | |
| HELP | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "help" button that normally is supposed to be on the right. Button order code: H | |
| HELP_2 | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "help2" button that normally is supposed to be on the left. Button order code: E | |
| LEFT | back to summary |
|---|---|
| public static final ButtonBar. Buttons with this style tag will statically end up on the left end of the bar. Button order code: L | |
| NEXT_FORWARD | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "next" or "forward" button. Is default button: True Button order code: X | |
| NO | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "no" button. Is cancel button: True Button order code: N | |
| OK_DONE | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "ok" or "done" button. Is default button: True Button order code: O | |
| OTHER | back to summary |
|---|---|
| public static final ButtonBar. All Uncategorized, Other, or "Unknown" buttons. Tag will be "other". Button order code: U | |
| RIGHT | back to summary |
|---|---|
| public static final ButtonBar. Buttons with this style tag will statically end up on the right end of the bar. Button order code: R | |
| SMALL_GAP | back to summary |
|---|---|
| public static final ButtonBar. An "unrelated" gap. (Platform dependent) Button order code: _ (underscore) | |
| typeCode | back to summary |
|---|---|
| private final String typeCode | |
| YES | back to summary |
|---|---|
| public static final ButtonBar. A tag for the "yes" button. Is default button: True Button order code: Y | |
| ButtonData | back to summary |
|---|---|
| private ButtonData(String type, boolean cancelButton, boolean defaultButton) | |
| getTypeCode | back to summary |
|---|---|
| public String getTypeCode() Returns the single character code used to represent the ButtonData
annotation in the
| |
| isCancelButton | back to summary |
|---|---|
| public final boolean isCancelButton() Indicates whether buttons created from the ButtonData enumeration should be the 'cancel' button in the user interface. This typically means that the button will respond to the escape key press, even if the button does not have focus. ButtonData enumeration values that can be the cancel button have a comment stating this in their javadoc.
| |
| isDefaultButton | back to summary |
|---|---|
| public final boolean isDefaultButton() Indicates whether buttons created from the ButtonData enumeration should be the 'default' button in the user interface. This typically means that the button will respond to enter key presses, even if the button does not have focus. ButtonData enumeration values that can be the default button have a comment stating this in their javadoc.
| |
| valueOf | back to summary |
|---|---|
| public static ButtonBar. | |
| values | back to summary |
|---|---|
| public static ButtonBar. | |