Class ButtonBar
- All Implemented Interfaces:
LayoutMeasurable,LayoutMeasurableMixin,HasBackgroundProperty,HasBlendModeProperty,HasBorderProperty,HasClipProperty,HasEffectProperty,HasHeightProperty,HasLayoutXProperty,HasLayoutYProperty,HasManagedProperty,HasMaxHeightProperty,HasMaxWidthProperty,HasMinHeightProperty,HasMinWidthProperty,HasMouseTransparentProperty,HasOnMouseClickedProperty,HasOpacityProperty,HasPaddingProperty,HasParentProperty,HasPrefHeightProperty,HasPrefWidthProperty,HasSnapToPixelProperty,HasVisibleProperty,HasWidthProperty,Styleable,EventTarget,Skinnable,INode,PreferenceResizableNode
HBox, with the additional functionality
for operating system specific button placement. In other words, any Node may
be annotated (via the 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:
| 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 ButtonBar.ButtonData enumeration for a description of
what each of these characters mean. However, if your ButtonBar only consisted
of ButtonBar.ButtonData.YES and ButtonBar.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:
-
Property Summary
PropertiesTypePropertyDescriptionfinal DoublePropertySpecifies the minimum width of all buttons placed in this button bar.final StringPropertyThe order for the typical buttons in a standard button bar.Properties inherited from class javafx.scene.control.Control
contextMenu, skin, tooltipProperties inherited from class javafx.scene.layout.Region
background, border, height, insets, maxHeight, maxWidth, minHeight, minWidth, padding, prefHeight, prefWidth, snapToPixel, widthProperties inherited from class javafx.scene.Parent
needsLayoutProperties inherited from class javafx.scene.Node
blendMode, cacheHint, cache, clip, cursor, disabled, disable, effect, eventDispatcher, focused, focusTraversable, hover, id, layoutBounds, layoutX, layoutY, managed, mouseTransparent, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragged, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onScroll, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, opacity, parent, pressed, rotate, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, visibleProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasBlendModeProperty
blendModeProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasClipProperty
clipProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasEffectProperty
effectProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasLayoutXProperty
layoutXProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasLayoutYProperty
layoutYProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasManagedProperty
managedProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMouseTransparentProperty
mouseTransparentProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasOnMouseClickedProperty
onMouseClickedProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasOpacityProperty
opacityProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasParentProperty
parentProperties inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasVisibleProperty
visible -
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAn enumeration of all available button data annotations. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default button ordering on Linux (specifically, GNOME).static final StringThe default button ordering on Mac OS.static final StringA button ordering string that specifies there is no button ordering.static final StringThe default button ordering on Windows.Fields inherited from interface javafx.scene.INode
BASELINE_OFFSET_SAME_AS_HEIGHTFields inherited from interface javafx.scene.layout.PreferenceResizableNode
USE_COMPUTED_SIZE, USE_PREF_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionCreates a default ButtonBar instance using the default properties for the users operating system.Creates a ButtonBar with the given button order (refer tobuttonOrderProperty()for more information). -
Method Summary
Modifier and TypeMethodDescriptionfinal DoublePropertySpecifies the minimum width of all buttons placed in this button bar.final StringPropertyThe order for the typical buttons in a standard button bar.protected Skin<?>Create a new instance of the default skin for this control.static ButtonBar.ButtonDatagetButtonData(Node button) Returns the previously set ButtonData property on the given button.final doubleReturns the minimum width of all buttons placed in this button bar.final StringReturns the currentbutton order.final ObservableList<Node>Placing buttons inside this ObservableList will instruct the ButtonBar to position them relative to each other based on their specifiedButtonBar.ButtonData.static booleanisButtonUniformSize(Node button) Returns whether the given node is part of the uniform sizing calculations or not.static voidsetButtonData(Node button, ButtonBar.ButtonData buttonData) Sets the given ButtonData on the given button.final voidsetButtonMinWidth(double value) Sets the minimum width of all buttons placed in this button bar.final voidsetButtonOrder(String buttonOrder) Sets thebutton orderstatic voidsetButtonUniformSize(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.Methods inherited from class javafx.scene.control.Control
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getSkin, getTooltip, layoutChildren, setContextMenu, setSkin, setTooltip, shouldUseLayoutMeasurable, skinProperty, tooltipPropertyMethods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, boundedSize, getInsets, heightProperty, impl_computeGeomBounds, impl_computeLayoutBounds, impl_maxHeight, impl_maxWidth, impl_minHeight, impl_minWidth, impl_prefHeight, impl_prefWidth, insetsProperty, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeightProperty, maxWidthProperty, minHeightProperty, minWidthProperty, paddingProperty, positionInArea, positionInArea, prefHeightProperty, prefWidthProperty, resize, setMaxSize, setMinSize, setPrefSize, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthPropertyMethods inherited from class javafx.scene.Parent
getChildren, getChildrenUnmodifiable, getManagedChildren, isNeedsLayout, layout, needsLayoutProperty, requestLayout, requestParentLayout, setLayoutFlag, setNeedsLayout, setSceneRootMethods inherited from class javafx.scene.Node
addEventFilter, addEventHandler, autosize, blendModeProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, createLayoutMeasurable, cursorProperty, disabledProperty, disableProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAllNodeTransforms, getBoundsInLocal, getCacheHint, getCursor, getEventDispatcher, getId, getLayoutMeasurable, getNodePeer, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseDragged, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnScroll, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOrCreateAndBindNodePeer, getProperties, getRotate, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleClass, getTransforms, getTranslateX, getTranslateY, getUserData, hasProperties, hoverProperty, idProperty, impl_getLayoutBounds, impl_isTreeVisible, impl_traverse, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isPressed, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToScene, localToScene, localToScreen, localToScreen, localToScreen, localToScreen, managedProperty, mouseTransparentProperty, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDraggedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onNodePeerReady, onPeerSizeChanged, onScrollProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, opacityProperty, parentProperty, parentToLocal, pressedProperty, removeEventFilter, removeEventHandler, requestFocus, requestPeerFocus, rotateProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, setCache, setCacheHint, setCursor, setDisable, setDisabled, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setNodePeer, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseDragged, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnScroll, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setPressed, setRotate, setScaleX, setScaleY, setScaleZ, setScene, setStyle, setTranslateX, setTranslateY, setUserData, snapshot, startDragAndDrop, styleProperty, toBack, toFront, translateXProperty, translateYProperty, visiblePropertyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasBackgroundProperty
getBackground, setBackgroundMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasBlendModeProperty
blendModeProperty, getBlendMode, setBlendModeMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasBorderProperty
getBorder, setBorderMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasClipProperty
clipProperty, getClip, setClipMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasEffectProperty
effectProperty, getEffect, setEffectMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasHeightProperty
getHeight, setHeightMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasLayoutXProperty
getLayoutX, layoutXProperty, setLayoutXMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasLayoutYProperty
getLayoutY, layoutYProperty, setLayoutYMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasManagedProperty
isManaged, managedProperty, setManagedMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMaxHeightProperty
getMaxHeight, setMaxHeightMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMaxWidthProperty
getMaxWidth, setMaxWidthMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMinHeightProperty
getMinHeight, setMinHeightMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMinWidthProperty
getMinWidth, setMinWidthMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasMouseTransparentProperty
isMouseTransparent, mouseTransparentProperty, setMouseTransparentMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasOnMouseClickedProperty
getOnMouseClicked, onMouseClickedProperty, setOnMouseClickedMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasOpacityProperty
getOpacity, opacityProperty, setOpacityMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasPaddingProperty
getPadding, setPaddingMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasParentProperty
getParent, parentProperty, setParentMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasPrefHeightProperty
getPrefHeight, setPrefHeightMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasPrefWidthProperty
getPrefWidth, setPrefWidthMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasSnapToPixelProperty
isSnapToPixel, setSnapToPixelMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasVisibleProperty
isVisible, setVisible, visiblePropertyMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasWidthProperty
getWidth, setWidthMethods inherited from interface javafx.scene.INode
autosize, getAllNodeTransforms, getContentBias, getNodePeer, getOrCreateAndBindNodePeer, getProperties, getScene, getTransforms, hasProperties, relocate, resizeRelocateMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.emul_coupling.LayoutMeasurableMixin
clearCache, getLayoutBounds, getLayoutMeasurable, maxHeight, maxWidth, minHeight, minWidth, prefHeight, prefWidthMethods inherited from interface javafx.scene.layout.PreferenceResizableNode
isResizable
-
Property Details
-
buttonOrder
The order for the typical buttons in a standard button bar. It is one letter perButtonBar.ButtonDataenumeration value. Default button orders for operating systems are also available:BUTTON_ORDER_WINDOWS,BUTTON_ORDER_MAC_OS, andBUTTON_ORDER_LINUX. -
buttonMinWidth
Specifies the minimum width of all buttons placed in this button bar.
-
-
Field Details
-
BUTTON_ORDER_WINDOWS
The default button ordering on Windows.- See Also:
-
BUTTON_ORDER_MAC_OS
The default button ordering on Mac OS.- See Also:
-
BUTTON_ORDER_LINUX
The default button ordering on Linux (specifically, GNOME).- See Also:
-
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 thegetButtons()list. The only aspect of layout that makes this different than using an HBox is that the buttons are right-aligned.- See Also:
-
-
Constructor Details
-
ButtonBar
public ButtonBar()Creates a default ButtonBar instance using the default properties for the users operating system. -
ButtonBar
Creates a ButtonBar with the given button order (refer tobuttonOrderProperty()for more information).- Parameters:
buttonOrder- The button order to use in this button bar instance.
-
-
Method Details
-
setButtonData
Sets the given ButtonData on the given button. If this button is subsequently placed in aButtonBarit will be placed in the correct position relative to all other buttons in the bar.- Parameters:
button- The button to annotate with the givenButtonBar.ButtonDatavalue.buttonData- The ButtonData to designate the button as.
-
getButtonData
Returns the previously set ButtonData property on the given button. If this was never set, this method will return null.- Parameters:
button- The button to return the previously set ButtonData for.
-
setButtonUniformSize
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- The button to include / exclude from uniform sizing.uniformSize- Boolean true to force uniform sizing on the button, false to exclude the button from uniform sizing.
-
isButtonUniformSize
Returns whether the given node is part of the uniform sizing calculations or not. By default all nodes that have not opted out (viasetButtonUniformSize(Node, boolean)) will return true here. -
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-skinor set explicitly in a sub-class withsetSkin(...).- Overrides:
createDefaultSkinin classControl- Returns:
- new instance of default skin for this control. If null then the control will have no skin unless one is provided by css.
-
getButtons
Placing buttons inside this ObservableList will instruct the ButtonBar to position them relative to each other based on their specifiedButtonBar.ButtonData. To set the ButtonData for a button, simply callsetButtonData(Node, ButtonData), passing in the relevant ButtonData.- Returns:
- A list containing all buttons currently in the button bar, and allowing for further buttons to be added or removed.
-
buttonOrderProperty
The order for the typical buttons in a standard button bar. It is one letter perButtonBar.ButtonDataenumeration value. Default button orders for operating systems are also available:BUTTON_ORDER_WINDOWS,BUTTON_ORDER_MAC_OS, andBUTTON_ORDER_LINUX.- Returns:
- the
buttonOrderproperty - See Also:
-
setButtonOrder
Sets thebutton order- Parameters:
buttonOrder- The currently set button order, which by default will be the OS-specific button order.
-
getButtonOrder
Returns the currentbutton order.- Returns:
- The current
button order.
-
buttonMinWidthProperty
Specifies the minimum width of all buttons placed in this button bar.- Returns:
- the
buttonMinWidthproperty - See Also:
-
setButtonMinWidth
public final void setButtonMinWidth(double value) Sets the minimum width of all buttons placed in this button bar. -
getButtonMinWidth
public final double getButtonMinWidth()Returns the minimum width of all buttons placed in this button bar.
-