public final class ButtonBar extends Control
HBox for controls extending
ButtonBase, most notably Button, which have been annotated
with a specific type (from the ButtonBar.ButtonType enumeration). By applying
this annotation, the ButtonBar is able to place the buttons in their correct
relative positions based on either OS-specific locations, or in an application
specific application (by setting the button order).
The concept and API for this control borrows heavily from the MigLayout button bar functionality.
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:
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.setType(yesButton, ButtonBar.ButtonType.YES);
Button noButton = new Button("No");
ButtonBar.setType(noButton, ButtonBar.ButtonType.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+FBI_YNOCAH_R |
| Mac OS: | L_HE+U+FBI_NCYOA_R |
| Linux: | L_HE+UNYACBXIO_R |
You should refer to the ButtonBar.ButtonType enumeration for a description of
what each of these characters mean. However, if your ButtonBar only consisted
of ButtonBar.ButtonType.YES and ButtonBar.ButtonType.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");
| Type | Property and Description |
|---|---|
DoubleProperty |
buttonMinWidth
Specifies the minimum width of all buttons placed in this button bar.
|
StringProperty |
buttonOrder
The order for the typical buttons in a standard button bar.
|
BooleanProperty |
buttonUniformSize
Specifies that all buttons in the button bar should be the same size.
|
contextMenuProperty, skinClassNameProperty, skinProperty, tooltipPropertybackgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, heightProperty, insetsProperty, maxHeightProperty, maxWidthProperty, minHeightProperty, minWidthProperty, opaqueInsetsProperty, paddingProperty, prefHeightProperty, prefWidthProperty, scaleShapeProperty, shapeProperty, snapToPixelProperty, widthPropertyimpl_traversalEngineProperty, needsLayoutPropertyblendModeProperty, boundsInLocalProperty, boundsInParentProperty, cacheHintProperty, cacheProperty, clipProperty, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, focusedProperty, focusTraversableProperty, hoverProperty, idProperty, impl_showMnemonicsProperty, impl_treeVisibleProperty, inputMethodRequestsProperty, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParentTransformProperty, localToSceneTransformProperty, managedProperty, mouseTransparentProperty, nodeOrientationProperty, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, pickOnBoundsProperty, pressedProperty, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, styleProperty, translateXProperty, translateYProperty, translateZProperty, visibleProperty| Modifier and Type | Class and Description |
|---|---|
static class |
ButtonBar.ButtonType
An enumeration of all available button types.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
BUTTON_ORDER_LINUX
The default button ordering on Linux (specifically, GNOME).
|
static String |
BUTTON_ORDER_MAC_OS
The default button ordering on Mac OS.
|
static String |
BUTTON_ORDER_WINDOWS
The default button ordering on Windows.
|
USE_COMPUTED_SIZE, USE_PREF_SIZEBASELINE_OFFSET_SAME_AS_HEIGHT| Constructor and Description |
|---|
ButtonBar()
Creates a default ButtonBar instance using the default properties for
the users operating system.
|
ButtonBar(String buttonOrder)
Creates a ButtonBar with the given button order (refer to
buttonOrderProperty() for more information). |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addButton(ButtonBase button,
ButtonBar.ButtonType buttonType)
A convenience method which is a shortcut for code of the following form:
Button detailsButton = createDetailsButton();
ButtonBar.setType(detailsButton, ButtonType.HELP_2);
buttonBar.getButtons().add(detailsButton);
|
boolean |
addSizeIndependentButton(ButtonBase button,
ButtonBar.ButtonType buttonType)
A convenience method which is a shortcut for code of the following form:
Button detailsButton = createDetailsButton();
ButtonBar.setType(detailsButton, ButtonType.HELP_2);
ButtonBar.setSizeIndependent(detailsButton);
buttonBar.getButtons().add(detailsButton);
|
DoubleProperty |
buttonMinWidthProperty()
Specifies the minimum width of all buttons placed in this button bar.
|
StringProperty |
buttonOrderProperty()
The order for the typical buttons in a standard button bar.
|
BooleanProperty |
buttonUniformSizeProperty()
Specifies that all buttons in the button bar should be the same size.
|
protected Skin<?> |
createDefaultSkin() |
double |
getButtonMinWidth()
Returns the minimum width of all buttons placed in this button bar.
|
String |
getButtonOrder()
Returns the current
button order. |
ObservableList<ButtonBase> |
getButtons()
Placing buttons inside this ObservableList will instruct the ButtonBar
to position them relative to each other based on their specified
ButtonBar.ButtonType. |
boolean |
isButtonUniformSize()
Checks if all buttons should have uniform size
|
void |
setButtonMinWidth(double value)
Sets the minimum width of all buttons placed in this button bar.
|
void |
setButtonOrder(String buttonOrder)
Sets the
button order |
void |
setButtonUniformSize(boolean value)
Sets all buttons to be uniform size
|
static void |
setSizeIndependent(Action action)
Excludes action from uniform resizing
|
static void |
setSizeIndependent(ButtonBase button)
Excludes button from uniform resizing
|
static void |
setType(Action action,
ButtonBar.ButtonType type)
|
static void |
setType(ButtonBase button,
ButtonBar.ButtonType type)
Sets the given ButtonType on the given button.
|
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getClassCssMetaData, getContextMenu, getControlCssMetaData, getCssMetaData, getSkin, getTooltip, getUserAgentStylesheet, impl_cssGetFocusTraversableInitialValue, impl_processCSS, isResizable, layoutChildren, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipPropertybackgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getWidth, heightProperty, impl_computeContains, impl_computeGeomBounds, impl_computeLayoutBounds, impl_createPeer, impl_notifyLayoutBoundsChanged, impl_pickNodeLocal, impl_updatePeer, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapSize, snapSpace, snapToPixelProperty, widthPropertygetChildren, getChildrenUnmodifiable, getImpl_traversalEngine, getManagedChildren, getStylesheets, impl_getAllParentStylesheets, impl_processMXNode, impl_traversalEngineProperty, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setImpl_traversalEngine, setNeedsLayout, updateBoundsaddEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, containsBounds, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, hasProperties, hoverProperty, idProperty, impl_clearDirty, impl_computeIntersects, impl_cssGetCursorInitialValue, impl_geomChanged, impl_getAccessible, impl_getLeafTransform, impl_getMatchingStyles, impl_getPeer, impl_getPivotX, impl_getPivotY, impl_getPivotZ, impl_getStyleMap, impl_hasTransforms, impl_intersects, impl_intersectsBounds, impl_isDirty, impl_isDirtyEmpty, impl_isShowMnemonics, impl_isTreeVisible, impl_layoutBoundsChanged, impl_markDirty, impl_pickNode, impl_processCSS, impl_reapplyCSS, impl_setShowMnemonics, impl_setStyleMap, impl_showMnemonicsProperty, impl_syncPeer, impl_transformsChanged, impl_traverse, impl_treeVisibleProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, visiblePropertypublic final StringProperty buttonOrderProperty
ButtonBar.ButtonType. Default button orders for operating systems are also
available: BUTTON_ORDER_WINDOWS, BUTTON_ORDER_MAC_OS,
BUTTON_ORDER_LINUX.getButtonOrder(),
setButtonOrder(String)public final DoubleProperty buttonMinWidthProperty
getButtonMinWidth(),
setButtonMinWidth(double)public final BooleanProperty buttonUniformSizeProperty
public static final String BUTTON_ORDER_WINDOWS
public static final String BUTTON_ORDER_MAC_OS
public static final String BUTTON_ORDER_LINUX
public ButtonBar()
public ButtonBar(String buttonOrder)
buttonOrderProperty() for more information).buttonOrder - The button order to use in this button bar instance.public static void setType(ButtonBase button, ButtonBar.ButtonType type)
ButtonBar it will be placed in the
correct position relative to all other buttons in the bar.button - The button to tag with the given type.type - The type to designate the button as.public static void setSizeIndependent(ButtonBase button)
button - button to excludepublic static void setType(Action action, ButtonBar.ButtonType type)
Action If this action is
subsequently placed in a ButtonBar it will be placed in the
correct position relative to all other buttons in the bar.action - The action to tag with the given type.type - The type to designate the action as.public static void setSizeIndependent(Action action)
action - action to excludeprotected Skin<?> createDefaultSkin()
createDefaultSkin in class Controlpublic ObservableList<ButtonBase> getButtons()
ButtonBar.ButtonType. To set the ButtonType for a button, simply call
setType(ButtonBase, ButtonType), passing in the
relevant ButtonType.public boolean addButton(ButtonBase button, ButtonBar.ButtonType buttonType)
Button detailsButton = createDetailsButton();
ButtonBar.setType(detailsButton, ButtonType.HELP_2);
buttonBar.getButtons().add(detailsButton);
button - The button to add to this button bar instance.buttonType - The type of the button, such that it can be place correctly.public boolean addSizeIndependentButton(ButtonBase button, ButtonBar.ButtonType buttonType)
Button detailsButton = createDetailsButton();
ButtonBar.setType(detailsButton, ButtonType.HELP_2);
ButtonBar.setSizeIndependent(detailsButton);
buttonBar.getButtons().add(detailsButton);
button - The button to add to this button bar instance.buttonType - The type of the button, such that it can be place correctly.public final StringProperty buttonOrderProperty()
ButtonBar.ButtonType. Default button orders for operating systems are also
available: BUTTON_ORDER_WINDOWS, BUTTON_ORDER_MAC_OS,
BUTTON_ORDER_LINUX.getButtonOrder(),
setButtonOrder(String)public final void setButtonOrder(String buttonOrder)
button orderbuttonOrder - The currently set button order, which by default will
be the OS-specific button order.public final String getButtonOrder()
button order.button order.public final DoubleProperty buttonMinWidthProperty()
getButtonMinWidth(),
setButtonMinWidth(double)public final void setButtonMinWidth(double value)
public final double getButtonMinWidth()
public final BooleanProperty buttonUniformSizeProperty()
public final void setButtonUniformSize(boolean value)
value - true if size should be uniform otherwise preferred size is usedpublic final boolean isButtonUniformSize()