- java.lang.Object
-
- javafx.scene.Node
-
- javafx.scene.Parent
-
- javafx.scene.layout.Region
-
- javafx.scene.control.Control
-
- javafx.scene.control.ButtonBar
-
- All Implemented Interfaces:
-
Styleable
,EventTarget
,Skinnable
public class ButtonBar extends Control
ButtonBar本质上是一个HBox
,具有操作系统特定按钮放置的附加功能。 换句话说,任何节点都可以被注释(通过setButtonData(Node, ButtonData)
方法,放置在ButtonBar内(通过getButtons()
列表),然后根据它们的注释将其定位在按钮列表中的所有其他节点以及总体上为ButtonBar指定的button order
。均匀按钮尺寸
默认情况下,所有按钮在ButtonBar中均匀的大小,这意味着所有按钮都占据最宽按钮的宽度。 可以根据每个按钮选择退出,但是使用布尔值为false调用
setButtonUniformSize(Node, boolean)
方法。如果一个按钮被排除在均匀尺寸之外,那么它们都不能从其首选尺寸被调整大小,并且也被排除在测量过程之外,因此其尺寸不会影响对ButtonBar中所有按钮计算的最大尺寸。
截图
由于ButtonBar具有Windows,Mac OS和Linux的内置支持,所以下面显示了三个屏幕截图,在三个操作系统中都有相同的按钮。
视窗:
Mac OS: Linux的:代码示例
实例化和使用ButtonBar很简单,只需执行以下操作:
// 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);
上面的代码示例将相对于用户操作系统定位“是”和“否”按钮。 这意味着在Windows和Linux上,Yes按钮将出现在No按钮之前,而在Mac OS上,它将为No,然后是Yes。
在大多数情况下,操作系统特定的布局是最佳选择,但是在需要自定义布局的情况下,可以修改
ButtonBar Layout Table Windows: L_E+U+FBXI_YNOCAH_R Mac OS: L_HE+U+FBIX_NCYOA_R Linux: L_HE+UNYACBXIO_Rbutton order property
。 这些是令人难以置信的字符串,它们是按钮顺序的缩写。 Windows,Mac OS和Linux的内置订单有:您应该参考
ButtonBar.ButtonData
枚举来说明这些字符是什么意思。 但是,如果您的ButtonBar仅包含ButtonBar.ButtonData.YES
和ButtonBar.ButtonData.NO
按钮,则您始终想要在no按钮之前的是按钮,并且您希望按钮为right-aligned
,则可以执行以下操作:// Create the ButtonBar instance ButtonBar buttonBar = new ButtonBar(); // Set the custom button order buttonBar.setButtonOrder("+YN");
- 从以下版本开始:
- JavaFX 8u40
- 另请参见:
-
ButtonBar.ButtonData
-
-
Property Summary
Properties Type Property 描述 DoubleProperty
buttonMinWidth
指定放置在此按钮栏中的所有按钮的最小宽度。StringProperty
buttonOrder
标准按钮栏中典型按钮的顺序。-
Properties inherited from class javafx.scene.control.Control
contextMenu, skin, tooltip
-
Properties inherited from class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
-
Properties inherited from class javafx.scene.Parent
needsLayout
-
Properties inherited from class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 static class
ButtonBar.ButtonData
枚举所有可用的按钮数据注释。
-
Field Summary
Fields Modifier and Type Field 描述 static String
BUTTON_ORDER_LINUX
Linux上的默认按钮排序(特别是GNOME)。static String
BUTTON_ORDER_MAC_OS
Mac OS上的默认按钮排序。static String
BUTTON_ORDER_NONE
一个按钮排序字符串,指定没有按钮排序。static String
BUTTON_ORDER_WINDOWS
Windows上的默认按钮排序。-
Fields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
-
Fields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
-
-
构造方法摘要
构造方法 Constructor 描述 ButtonBar()
使用用户操作系统的默认属性创建默认的ButtonBar实例。ButtonBar(String buttonOrder)
使用给定的按钮顺序创建ButtonBar(有关详细信息,请参阅buttonOrderProperty()
)。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 DoubleProperty
buttonMinWidthProperty()
指定放置在此按钮栏中的所有按钮的最小宽度。StringProperty
buttonOrderProperty()
标准按钮栏中典型按钮的顺序。protected Skin<?>
createDefaultSkin()
为此控件创建一个新的默认皮肤实例。static ButtonBar.ButtonData
getButtonData(Node button)
返回给定按钮上先前设置的ButtonData属性。double
getButtonMinWidth()
返回放置在此按钮栏中的所有按钮的最小宽度。String
getButtonOrder()
返回当前的button order
。ObservableList<Node>
getButtons()
在此ObservableList内放置按钮将指示ButtonBar根据其指定的ButtonBar.ButtonData
将它们相对放置 。protected Boolean
getInitialFocusTraversable()
返回此控件的初始焦点遍历状态,供JavaFX CSS引擎正确设置其初始值。static boolean
isButtonUniformSize(Node button)
返回给定节点是否是统一尺寸计算的一部分。static void
setButtonData(Node button, ButtonBar.ButtonData buttonData)
在给定的按钮上设置给定的ButtonData。void
setButtonMinWidth(double value)
设置放置在此按钮栏中的所有按钮的最小宽度。void
setButtonOrder(String buttonOrder)
设置button order
static void
setButtonUniformSize(Node button, boolean uniformSize)
默认情况下,所有按钮在ButtonBar中均匀的大小,这意味着所有按钮都占据最宽按钮的宽度。-
Methods inherited from class javafx.scene.control.Control
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, executeAccessibleAction, getBaselineOffset, getClassCssMetaData, getContextMenu, getControlCssMetaData, getCssMetaData, getSkin, getTooltip, isResizable, layoutChildren, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty
-
Methods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, 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, getViewOrder, hasProperties, hoverProperty, idProperty, 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, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, 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, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, 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, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from class javafx.scene.Parent
getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
-
Methods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, 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, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
-
Methods inherited from interface javafx.css.Styleable
getStyleableNode
-
-
-
-
Property Detail
-
buttonOrder
public final StringProperty buttonOrderProperty
标准按钮栏中典型按钮的顺序。 它是每个ButtonBar.ButtonData
枚举值一个字母。 对于操作系统的默认按钮的订单也可用:BUTTON_ORDER_WINDOWS
,BUTTON_ORDER_MAC_OS
,并BUTTON_ORDER_LINUX
。
-
buttonMinWidth
public final DoubleProperty buttonMinWidthProperty
指定放置在此按钮栏中的所有按钮的最小宽度。
-
-
字段详细信息
-
BUTTON_ORDER_WINDOWS
public static final String BUTTON_ORDER_WINDOWS
Windows上的默认按钮排序。- 另请参见:
- Constant Field Values
-
BUTTON_ORDER_MAC_OS
public static final String BUTTON_ORDER_MAC_OS
Mac OS上的默认按钮排序。- 另请参见:
- Constant Field Values
-
BUTTON_ORDER_LINUX
public static final String BUTTON_ORDER_LINUX
Linux上的默认按钮排序(特别是GNOME)。- 另请参见:
- Constant Field Values
-
BUTTON_ORDER_NONE
public static final String BUTTON_ORDER_NONE
- 另请参见:
- Constant Field Values
-
-
构造方法详细信息
-
ButtonBar
public ButtonBar()
使用用户操作系统的默认属性创建默认的ButtonBar实例。
-
ButtonBar
public ButtonBar(String buttonOrder)
使用给定的按钮顺序创建ButtonBar(有关详细信息,请参阅buttonOrderProperty()
)。- 参数
-
buttonOrder
- 在此按钮栏实例中使用的按钮顺序。
-
-
方法详细信息
-
setButtonData
public static void setButtonData(Node button, ButtonBar.ButtonData buttonData)
在给定的按钮上设置给定的ButtonData。 如果此按钮随后放置在ButtonBar
中 ,它将被放置在相对于条中所有其他按钮的正确位置。- 参数
-
button
- 使用给定的ButtonBar.ButtonData
值进行注释的按钮。 -
buttonData
- ButtonData将按钮指定为。
-
getButtonData
public static ButtonBar.ButtonData getButtonData(Node button)
返回给定按钮上先前设置的ButtonData属性。 如果没有设置,这个方法将返回null。- 参数
-
button
- 返回之前设置的ButtonData的按钮。 - 结果
- 给定按钮上先前设置的ButtonData属性
-
setButtonUniformSize
public static void setButtonUniformSize(Node button, boolean uniformSize)
默认情况下,所有按钮在ButtonBar中均匀的大小,这意味着所有按钮都占据最宽按钮的宽度。 可以根据每个按钮选择退出,但是使用布尔值为false调用setButtonUniformSize方法。如果一个按钮被排除在均匀尺寸之外,那么它们都不能从其首选尺寸被调整大小,并且也被排除在测量过程之外,因此其尺寸不会影响对ButtonBar中所有按钮计算的最大尺寸。
- 参数
-
button
- 包含/排除统一尺寸的按钮。 -
uniformSize
- 布尔值true以强制按钮上的均匀尺寸,false将排除按钮的均匀尺寸。
-
isButtonUniformSize
public static boolean isButtonUniformSize(Node button)
返回给定节点是否是统一尺寸计算的一部分。 默认情况下,所有未选择退出的节点(通过setButtonUniformSize(Node, boolean)
)将在此返回true。- 参数
-
button
- 按钮 - 结果
- 如果按钮是统一尺寸计算的一部分,则为true
-
createDefaultSkin
protected Skin<?> createDefaultSkin()
为此控件创建一个新的默认皮肤实例。 如果没有通过CSS-fx-skin
提供皮肤,或者在具有setSkin(...)
的子类中显式设置,则调用此控件创建皮肤。- 重写:
-
createDefaultSkin
在Control
- 结果
- 此控件的默认皮肤的新实例。 如果为null,则控件将没有皮肤,除非由css提供。
-
getButtons
public final ObservableList<Node> getButtons()
在此ObservableList内放置按钮将指示ButtonBar根据其指定的ButtonBar.ButtonData
将它们相对于彼此定位 。 要设置ButtonData为一个按钮,只需调用setButtonData(Node, ButtonData)
,传递相关的ButtonData。- 结果
- 包含当前按钮栏中所有按钮的列表,并允许添加或删除其他按钮。
-
buttonOrderProperty
public final StringProperty buttonOrderProperty()
标准按钮栏中典型按钮的顺序。 每个ButtonBar.ButtonData
一个字母的枚举值。 对于操作系统的默认按钮的订单也可用:BUTTON_ORDER_WINDOWS
,BUTTON_ORDER_MAC_OS
,并BUTTON_ORDER_LINUX
。
-
setButtonOrder
public final void setButtonOrder(String buttonOrder)
设置button order
- 参数
-
buttonOrder
- 当前设置的按钮顺序,默认情况下将是特定于操作系统的按钮顺序。
-
getButtonOrder
public final String getButtonOrder()
返回当前的button order
。- 结果
-
目前
button order
。
-
buttonMinWidthProperty
public final DoubleProperty buttonMinWidthProperty()
指定放置在此按钮栏中的所有按钮的最小宽度。
-
setButtonMinWidth
public final void setButtonMinWidth(double value)
设置放置在此按钮栏中的所有按钮的最小宽度。- 参数
-
value
- 最小宽度值
-
getButtonMinWidth
public final double getButtonMinWidth()
返回放置在此按钮栏中的所有按钮的最小宽度。- 结果
- 最小宽度值
-
getInitialFocusTraversable
protected Boolean getInitialFocusTraversable()
返回此控件的初始焦点遍历状态,供JavaFX CSS引擎正确设置其初始值。 该方法被覆盖,因为默认情况下UI控件将focus遍历设置为true,但这不适用于此控件。- 重写:
-
getInitialFocusTraversable
在Control
- 结果
- 该控件的初始聚焦可移动状态
- 从以下版本开始:
- 9
-
-