Top Description Inners Fields Constructors Methods
javafx.scene.control

public Class ButtonBar

extends Control
Class Inheritance
Imports
com.sun.javafx.scene.control.Properties, javafx.beans.property.DoubleProperty, .ObjectProperty, .SimpleDoubleProperty, .SimpleObjectProperty, .SimpleStringProperty, .StringProperty, javafx.collections.FXCollections, .ObservableList, javafx.scene.Node, javafx.scene.layout.HBox, com.sun.javafx.util.Utils, javafx.scene.control.skin.ButtonBarSkin, javafx.css.StyleableProperty, java.util.Map

A ButtonBar is essentially a 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.

Uniform button sizing

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.

Screenshots

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:

Mac OS:

Linux:

Code Samples

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:

ButtonBar Layout Table
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");
Since
JavaFX 8u40
See Also
ButtonData

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
ButtonBar.ButtonData

An enumeration of all available button data annotations.

Field Summary

Modifier and TypeField 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<Node>

Constructor Summary

AccessConstructor 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 buttonOrderProperty() for more information).

Method Summary

Modifier and TypeMethod and Description
public final DoubleProperty

Returns:

the minimum width property
buttonMinWidthProperty
()

Specifies the minimum width of all buttons placed in this button bar.

public final StringProperty

Returns:

the button order property
buttonOrderProperty
()

The order for the typical buttons in a standard button bar.

protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

public static ButtonBar.ButtonData

Returns:

the previously set ButtonData property on the given button
getButtonData
(Node
The 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 value
getButtonMinWidth
()

Returns the minimum width of all buttons placed in this button bar.

public final String

Returns:

The current button order.
getButtonOrder
()

Returns the current button order.

public final ObservableList<Node>

Returns:

A list containing all buttons currently in the button bar, and allowing for further buttons to be added or removed.
getButtons
()

Placing buttons inside this ObservableList will instruct the ButtonBar to position them relative to each other based on their specified ButtonData.

protected Boolean
getInitialFocusTraversable()

Overrides javafx.scene.control.Control.getInitialFocusTraversable.

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 calculations
isButtonUniformSize
(Node
the 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 ButtonData value.
button
,
ButtonBar.ButtonData
The ButtonData to designate the button as.
buttonData
)

Sets 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 button order

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.

Inherited from javafx.scene.control.Control:
computeMaxHeightcomputeMaxWidthcomputeMinHeightcomputeMinWidthcomputePrefHeightcomputePrefWidthcontextMenuPropertyexecuteAccessibleActiongetBaselineOffsetgetClassCssMetaDatagetContextMenugetControlChildrengetControlCssMetaDatagetCssMetaDatagetSkingetTooltipisResizablelayoutChildrenloadSkinClassqueryAccessibleAttributesetContextMenusetSkinsetTooltipskinClassNamePropertyskinPropertytooltipProperty

Field Detail

BUTTON_ORDER_LINUXback to summary
public static final String BUTTON_ORDER_LINUX

The default button ordering on Linux (specifically, GNOME).

BUTTON_ORDER_MAC_OSback to summary
public static final String BUTTON_ORDER_MAC_OS

The default button ordering on Mac OS.

BUTTON_ORDER_NONEback 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 getButtons() list. The only aspect of layout that makes this different than using an HBox is that the buttons are right-aligned.

BUTTON_ORDER_WINDOWSback to summary
public static final String BUTTON_ORDER_WINDOWS

The default button ordering on Windows.

buttonMinWidthPropertyback to summary
private final DoubleProperty buttonMinWidthProperty
buttonOrderPropertyback to summary
private final StringProperty buttonOrderProperty
buttonsback to summary
private ObservableList<Node> buttons

Constructor Detail

ButtonBarback to summary
public ButtonBar()

Creates a default ButtonBar instance using the default properties for the users operating system.

ButtonBarback to summary
public ButtonBar(final String buttonOrder)

Creates a ButtonBar with the given button order (refer to buttonOrderProperty() for more information).

Parameters
buttonOrder:String

The button order to use in this button bar instance.

Method Detail

buttonMinWidthPropertyback to summary
public final DoubleProperty buttonMinWidthProperty()

Specifies the minimum width of all buttons placed in this button bar.

Returns:DoubleProperty

the minimum width property

buttonOrderPropertyback to summary
public final StringProperty buttonOrderProperty()

The order for the typical buttons in a standard button bar. It is one letter per ButtonData enumeration value. Default button orders for operating systems are also available: BUTTON_ORDER_WINDOWS, BUTTON_ORDER_MAC_OS, and BUTTON_ORDER_LINUX.

Returns:StringProperty

the button order property

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

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 -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
getButtonDataback to summary
public static ButtonBar.ButtonData getButtonData(Node button)

Returns the previously set ButtonData property on the given button. If this was never set, this method will return null.

Parameters
button:Node

The button to return the previously set ButtonData for.

Returns:ButtonBar.ButtonData

the previously set ButtonData property on the given button

getButtonMinWidthback to summary
public final double getButtonMinWidth()

Returns the minimum width of all buttons placed in this button bar.

Returns:double

the minimum width value

getButtonOrderback to summary
public final String getButtonOrder()

Returns the current button order.

Returns:String

The current button order.

getButtonsback to summary
public final ObservableList<Node> getButtons()

Placing buttons inside this ObservableList will instruct the ButtonBar to position them relative to each other based on their specified ButtonData. To set the ButtonData for a button, simply call ButtonBar#setButtonData(Node, ButtonData), passing in the relevant ButtonData.

Returns:ObservableList<Node>

A list containing all buttons currently in the button bar, and allowing for further buttons to be added or removed.

getInitialFocusTraversableback to summary
protected Boolean getInitialFocusTraversable()

Overrides javafx.scene.control.Control.getInitialFocusTraversable.

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.

Annotations
@Override
Since
9
isButtonUniformSizeback 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 setButtonUniformSize(Node, boolean)) will return true here.

Parameters
button:Node

the button

Returns:boolean

true if button is part of the uniform sizing calculations

setButtonDataback to summary
public static void setButtonData(Node button, ButtonBar.ButtonData buttonData)

Sets the given ButtonData on the given button. If this button is subsequently placed in a ButtonBar it will be placed in the correct position relative to all other buttons in the bar.

Parameters
button:Node

The button to annotate with the given ButtonData value.

buttonData:ButtonBar.ButtonData

The ButtonData to designate the button as.

setButtonMinWidthback to summary
public final void setButtonMinWidth(double value)

Sets the minimum width of all buttons placed in this button bar.

Parameters
value:double

the minimum width value

setButtonOrderback to summary
public final void setButtonOrder(String buttonOrder)

Sets the button order

Parameters
buttonOrder:String

The currently set button order, which by default will be the OS-specific button order.

setButtonUniformSizeback 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.

Parameters
button:Node

The button to include / exclude from uniform sizing.

uniformSize:boolean

Boolean true to force uniform sizing on the button, false to exclude the button from uniform sizing.

javafx.scene.control back to summary

public final Enum ButtonBar.ButtonData

extends Enum<ButtonBar.ButtonData>
Class Inheritance

An enumeration of all available button data annotations. By annotating every button in a 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.

Since
JavaFX 8u40

Field Summary

Modifier and TypeField and Description
public static final ButtonBar.ButtonData
APPLY

A tag for the "apply" button.

public static final ButtonBar.ButtonData
BACK_PREVIOUS

A tag for the "back" or "previous" button.

public static final ButtonBar.ButtonData
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.ButtonData
CANCEL_CLOSE

A tag for the "cancel" or "close" button.

private final boolean
private final boolean
public static final ButtonBar.ButtonData
FINISH

A tag for the "finish".

public static final ButtonBar.ButtonData
HELP

A tag for the "help" button that normally is supposed to be on the right.

public static final ButtonBar.ButtonData
HELP_2

A tag for the "help2" button that normally is supposed to be on the left.

public static final ButtonBar.ButtonData
LEFT

Buttons with this style tag will statically end up on the left end of the bar.

public static final ButtonBar.ButtonData
NEXT_FORWARD

A tag for the "next" or "forward" button.

public static final ButtonBar.ButtonData
NO

A tag for the "no" button.

public static final ButtonBar.ButtonData
OK_DONE

A tag for the "ok" or "done" button.

public static final ButtonBar.ButtonData
OTHER

All Uncategorized, Other, or "Unknown" buttons.

public static final ButtonBar.ButtonData
RIGHT

Buttons with this style tag will statically end up on the right end of the bar.

public static final ButtonBar.ButtonData
SMALL_GAP

An "unrelated" gap.

private final String
public static final ButtonBar.ButtonData
YES

A tag for the "yes" button.

Constructor Summary

AccessConstructor and Description
private
ButtonData(String type, boolean cancelButton, boolean defaultButton)

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the single character code used to represent the ButtonData annotation
getTypeCode
()

Returns the single character code used to represent the ButtonData annotation in the button order string.

public final boolean

Returns:

true if this is a 'cancel' button
isCancelButton
()

Indicates 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' button
isDefaultButton
()

Indicates whether buttons created from the ButtonData enumeration should be the 'default' button in the user interface.

public static ButtonBar.ButtonData
public static ButtonBar.ButtonData[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

APPLYback to summary
public static final ButtonBar.ButtonData APPLY

A tag for the "apply" button.

Button order code: A

BACK_PREVIOUSback to summary
public static final ButtonBar.ButtonData BACK_PREVIOUS

A tag for the "back" or "previous" button.

Button order code: B

BIG_GAPback to summary
public static final ButtonBar.ButtonData BIG_GAP

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_CLOSEback to summary
public static final ButtonBar.ButtonData CANCEL_CLOSE

A tag for the "cancel" or "close" button.

Is cancel button: True

Button order code: C

cancelButtonback to summary
private final boolean cancelButton
defaultButtonback to summary
private final boolean defaultButton
FINISHback to summary
public static final ButtonBar.ButtonData FINISH

A tag for the "finish".

Is default button: True

Button order code: I

HELPback to summary
public static final ButtonBar.ButtonData HELP

A tag for the "help" button that normally is supposed to be on the right.

Button order code: H

HELP_2back to summary
public static final ButtonBar.ButtonData HELP_2

A tag for the "help2" button that normally is supposed to be on the left.

Button order code: E

LEFTback to summary
public static final ButtonBar.ButtonData LEFT

Buttons with this style tag will statically end up on the left end of the bar.

Button order code: L

NEXT_FORWARDback to summary
public static final ButtonBar.ButtonData NEXT_FORWARD

A tag for the "next" or "forward" button.

Is default button: True

Button order code: X

NOback to summary
public static final ButtonBar.ButtonData NO

A tag for the "no" button.

Is cancel button: True

Button order code: N

OK_DONEback to summary
public static final ButtonBar.ButtonData OK_DONE

A tag for the "ok" or "done" button.

Is default button: True

Button order code: O

OTHERback to summary
public static final ButtonBar.ButtonData OTHER

All Uncategorized, Other, or "Unknown" buttons. Tag will be "other".

Button order code: U

RIGHTback to summary
public static final ButtonBar.ButtonData RIGHT

Buttons with this style tag will statically end up on the right end of the bar.

Button order code: R

SMALL_GAPback to summary
public static final ButtonBar.ButtonData SMALL_GAP

An "unrelated" gap. (Platform dependent)

Button order code: _ (underscore)

typeCodeback to summary
private final String typeCode
YESback to summary
public static final ButtonBar.ButtonData YES

A tag for the "yes" button.

Is default button: True

Button order code: Y

Constructor Detail

ButtonDataback to summary
private ButtonData(String type, boolean cancelButton, boolean defaultButton)

Method Detail

getTypeCodeback to summary
public String getTypeCode()

Returns the single character code used to represent the ButtonData annotation in the button order string.

Returns:String

the single character code used to represent the ButtonData annotation

isCancelButtonback 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.

Returns:boolean

true if this is a 'cancel' button

isDefaultButtonback 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.

Returns:boolean

true if this is a 'default' button

valueOfback to summary
public static ButtonBar.ButtonData valueOf(String name)
valuesback to summary
public static ButtonBar.ButtonData[] values()