-
- All Implemented Interfaces:
-
Styleable
,EventTarget
,Skinnable
- 已知直接子类:
-
SplitMenuButton
public class MenuButton extends ButtonBase
MenuButton是一个按钮,当点击或按下时,它将显示一个ContextMenu
。 MenuButton与Menu
控件共享一个非常相似的API,只要您设置items
ObservableList中应显示的项目,并且有一个Labeled.text
属性来指定MenuButton中显示的标签。如上所述,像Menu API本身一样,您会发现一个
items
ObservableList,您可以在其中提供从MenuItem
扩展的任何内容 。 有一些有用的子类MenuItem
包括RadioMenuItem
,CheckMenuItem
,Menu
,SeparatorMenuItem
和CustomMenuItem
。可以将MenuButton设置为在按钮的任意一侧显示其菜单。 这是使用
popupSide
属性指定的。 默认情况下,菜单出现在按钮下方。 但是,无论popupSide如何指定,如果没有足够的空间,ContextMenu
将会被巧妙地重新定位,最有可能是在MenuButton的对面。例:
MenuButton m = new MenuButton("Eats"); m.getItems().addAll(new MenuItem("Burger"), new MenuItem("Hot Dog"));
默认情况下,MenuButton启用助记符分配。
- 从以下版本开始:
- JavaFX 2.0
- 另请参见:
-
MenuItem
,Menu
,SplitMenuButton
-
-
Property Summary
Properties Type Property 描述 ObjectProperty<Side>
popupSide
表示ContextMenu
应该在哪一边打开与MenuButton相关的方面。ReadOnlyBooleanProperty
showing
指示ContextMenu
当前是否可见。-
Properties inherited from class javafx.scene.control.ButtonBase
armed, onAction
-
Properties inherited from class javafx.scene.control.Control
contextMenu, skin, tooltip
-
Properties inherited from class javafx.scene.control.Labeled
alignment, contentDisplay, ellipsisString, font, graphic, graphicTextGap, labelPadding, lineSpacing, mnemonicParsing, textAlignment, textFill, textOverrun, text, underline, wrapText
-
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
-
-
Field Summary
Fields Modifier and Type Field 描述 static EventType<Event>
ON_HIDDEN
当MenuButton弹出窗口被隐藏时调用。static EventType<Event>
ON_HIDING
调用的时候,菜单按钮弹出 将被隐藏。static EventType<Event>
ON_SHOWING
在MenuButton显示弹出窗口之前,在用户单击或以其他方式与MenuButton进行交互之后调用。static EventType<Event>
ON_SHOWN
在MenuButton显示弹出窗口后调用。-
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 描述 MenuButton()
创建一个新的空的菜单按钮。MenuButton(String text)
创建一个新的空的菜单按钮,给定的文本显示在按钮上。MenuButton(String text, Node graphic)
创建一个新的空的菜单按钮,给定的文本和图形显示在按钮上。MenuButton(String text, Node graphic, MenuItem... items)
创建一个新的菜单按钮,给定的文本和图形显示在按钮上,并将给定的项目插入到items
列表中。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 protected Skin<?>
createDefaultSkin()
为此控件创建一个新的默认皮肤实例。void
executeAccessibleAction(AccessibleAction action, Object... parameters)
该方法由辅助技术调用,请求执行由参数指示的动作。void
fire()
这没有影响。ObservableList<MenuItem>
getItems()
在此按钮菜单中显示的项目。Side
getPopupSide()
获取属性popupSide的值。void
hide()
隐藏ContextMenu
。boolean
isShowing()
获取显示的属性的值。ObjectProperty<Side>
popupSideProperty()
表示ContextMenu
应该在哪一面打开相对于MenuButton。void
setPopupSide(Side value)
设置属性popupSide的值。void
show()
显示ContextMenu
,假设该MenuButton未被禁用。ReadOnlyBooleanProperty
showingProperty()
指示ContextMenu
当前是否可见。-
Methods inherited from class javafx.scene.control.ButtonBase
arm, armedProperty, disarm, getOnAction, isArmed, onActionProperty, setOnAction
-
Methods inherited from class javafx.scene.control.Control
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty
-
Methods inherited from class javafx.scene.control.Labeled
alignmentProperty, contentDisplayProperty, ellipsisStringProperty, fontProperty, getAlignment, getClassCssMetaData, getContentBias, getContentDisplay, getControlCssMetaData, getEllipsisString, getFont, getGraphic, getGraphicTextGap, getInitialAlignment, getLabelPadding, getLineSpacing, getText, getTextAlignment, getTextFill, getTextOverrun, graphicProperty, graphicTextGapProperty, isMnemonicParsing, isUnderline, isWrapText, labelPaddingProperty, lineSpacingProperty, mnemonicParsingProperty, setAlignment, setContentDisplay, setEllipsisString, setFont, setGraphic, setGraphicTextGap, setLineSpacing, setMnemonicParsing, setText, setTextAlignment, setTextFill, setTextOverrun, setUnderline, setWrapText, textAlignmentProperty, textFillProperty, textOverrunProperty, textProperty, toString, underlineProperty, wrapTextProperty
-
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, 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, 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
-
showing
public final ReadOnlyBooleanProperty showingProperty
指示ContextMenu
当前是否可见。- 另请参见:
-
isShowing()
-
popupSide
public final ObjectProperty<Side> popupSideProperty
表示ContextMenu
应该在哪一边打开相对于MenuButton。 菜单项通常在两种情况下垂直布置。 例如,如果菜单按钮位于应用程序左边缘的垂直工具栏中,则可以将popupSide
更改为Side.RIGHT
,以使弹出窗口显示在MenuButton的右侧。- Default value:
-
Side.BOTTOM
- 另请参见:
-
getPopupSide()
,setPopupSide(Side)
-
-
构造方法详细信息
-
MenuButton
public MenuButton()
创建一个新的空的菜单按钮。 使用Labeled.setText(String)
,Labeled.setGraphic(Node)
和getItems()
设置内容。
-
MenuButton
public MenuButton(String text)
创建一个新的空的菜单按钮,给定的文本显示在按钮上。 使用Labeled.setGraphic(Node)
和getItems()
设置内容。- 参数
-
text
- 要在菜单按钮上显示的文字
-
MenuButton
public MenuButton(String text, Node graphic)
创建一个新的空的菜单按钮,给定的文本和图形显示在按钮上。 使用getItems()
设置内容。- 参数
-
text
- 要在菜单按钮上显示的文字 -
graphic
- 在菜单按钮上显示的图形
-
-
方法详细信息
-
getItems
public final ObservableList<MenuItem> getItems()
在此按钮菜单中显示的项目。 如果在运行时修改了ObservableList,菜单将按预期更新。常用控件包括包含
MenuItem
,CheckMenuItem
,RadioMenuItem
,当然Menu
,其中,如果添加到菜单,将成为一个子菜单。SeparatorMenuItem
是菜单项目ObservableList中另一个常用的节点。- 结果
- 此按钮菜单中的菜单项列表
-
isShowing
public final boolean isShowing()
获取显示的属性的值。- Property description:
-
指示
ContextMenu
当前是否可见。
-
showingProperty
public final ReadOnlyBooleanProperty showingProperty()
指示ContextMenu
当前是否可见。- 另请参见:
-
isShowing()
-
setPopupSide
public final void setPopupSide(Side value)
设置属性popupSide的值。- Property description:
-
表示
ContextMenu
应该在哪一面打开与MenuButton相关的方面。 菜单项通常在两种情况下垂直布置。 例如,如果菜单按钮位于应用程序左边缘的垂直工具栏中,则可以将popupSide
更改为Side.RIGHT
,以使弹出窗口显示在MenuButton的右侧。 - Default value:
-
Side.BOTTOM
-
getPopupSide
public final Side getPopupSide()
获取属性popupSide的值。- Property description:
-
表示
ContextMenu
应该在哪一面打开与MenuButton相关的方面。 菜单项通常在两种情况下垂直布置。 例如,如果菜单按钮位于应用程序左边缘的垂直工具栏中,则可以将popupSide
更改为Side.RIGHT
,以使弹出窗口显示在MenuButton的右侧。 - Default value:
-
Side.BOTTOM
-
popupSideProperty
public final ObjectProperty<Side> popupSideProperty()
表示ContextMenu
应该在哪一面打开与MenuButton相关的方面。 菜单项通常在两种情况下垂直布置。 例如,如果菜单按钮位于应用程序左边缘的垂直工具栏中,则可以将popupSide
更改为Side.RIGHT
,以使弹出窗口显示在MenuButton的右侧。- Default value:
-
Side.BOTTOM
- 另请参见:
-
getPopupSide()
,setPopupSide(Side)
-
show
public void show()
显示ContextMenu
,假设该MenuButton未被禁用。- 另请参见:
-
Node.isDisabled()
,isShowing()
-
hide
public void hide()
隐藏ContextMenu
。- 另请参见:
-
isShowing()
-
fire
public void fire()
这没有影响。- Specified by:
-
fire
在ButtonBase
-
createDefaultSkin
protected Skin<?> createDefaultSkin()
为此控件创建一个新的默认皮肤实例。 如果没有通过CSS-fx-skin
提供皮肤或者在具有setSkin(...)
的子类中显式设置,则会调用此控件创建皮肤。- 重写:
-
createDefaultSkin
在Control
- 结果
- 此控件的默认皮肤的新实例。 如果为null,则控件将没有皮肤,除非由css提供。
-
executeAccessibleAction
public void executeAccessibleAction(AccessibleAction action, Object... parameters)
该方法由辅助技术调用,请求执行由参数指示的动作。此方法通常被子类覆盖,以实现特定角色所需的操作。
如果未处理特定操作,则必须调用超类实现。- 重写:
-
executeAccessibleAction
在ButtonBase
- 参数
-
action
- 执行的动作 -
parameters
- 可选参数列表 - 另请参见:
-
AccessibleAction
-
-