public class MenuButton extends ButtonBase
ContextMenu
. A MenuButton shares a very similar API to the Menu
control, insofar that you set the items that should be shown in the
items
ObservableList, and there is a text
property to specify the
label shown within the MenuButton.
As mentioned, like the Menu API itself, you'll find an items
ObservableList
within which you can provide anything that extends from MenuItem
.
There are several useful subclasses of MenuItem
including
RadioMenuItem
, CheckMenuItem
, Menu
,
SeparatorMenuItem
and CustomMenuItem
.
A MenuButton can be set to show its menu on any side of the button. This is
specified using the popupSide
property. By default
the menu appears below the button. However, regardless of the popupSide specified,
if there is not enough room, the ContextMenu
will be
smartly repositioned, most probably to be on the opposite side of the
MenuButton.
Example:
MenuButton m = new MenuButton("Eats"); m.getItems().addAll(new MenuItem("Burger"), new MenuItem("Hot Dog"));
MnemonicParsing is enabled by default for MenuButton.
MenuItem
,
Menu
,
SplitMenuButton
Type | Property and Description |
---|---|
<any> |
onHidden
Called just after the
ContextMenu has been hidden. |
<any> |
onHiding
Called just prior to the
ContextMenu being hidden. |
<any> |
onShowing
Called just prior to the
ContextMenu being shown. |
<any> |
onShown
Called just after the
ContextMenu is shown. |
<any> |
popupSide
Indicates on which side the
ContextMenu should open in
relation to the MenuButton. |
ReadOnlyBooleanProperty |
showing
Indicates whether the
ContextMenu is currently visible. |
armedProperty, onActionProperty
alignmentProperty, contentDisplayProperty, ellipsisStringProperty, fontProperty, graphicProperty, graphicTextGapProperty, labelPaddingProperty, lineSpacingProperty, mnemonicParsingProperty, textAlignmentProperty, textFillProperty, textOverrunProperty, textProperty, underlineProperty, wrapTextProperty
contextMenuProperty, skinClassNameProperty, skinProperty, tooltipProperty
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
DEFAULT_STYLE_CLASS
*
Stylesheet Handling *
*
|
private <any> |
items
*
Properties *
*
|
static <any> |
ON_HIDDEN
Called when the MenuButton popup has been hidden.
|
static <any> |
ON_HIDING
Called when the MenuButton popup will be hidden.
|
static <any> |
ON_SHOWING
Called prior to the MenuButton showing its popup after the user
has clicked or otherwise interacted with the MenuButton.
|
static <any> |
ON_SHOWN
Called after the MenuButton has shown its popup.
|
private <any> |
onHidden |
private <any> |
onHiding |
private <any> |
onShowing |
private <any> |
onShown |
private <any> |
popupSide
Indicates on which side the
ContextMenu should open in
relation to the MenuButton. |
private static PseudoClass |
PSEUDO_CLASS_OPENVERTICALLY |
private static PseudoClass |
PSEUDO_CLASS_SHOWING |
private ReadOnlyBooleanWrapper |
showing
Indicates whether the
ContextMenu is currently visible. |
Constructor and Description |
---|
MenuButton()
Creates a new empty menu button.
|
MenuButton(java.lang.String text)
Creates a new empty menu button with the given text to display on the
button.
|
MenuButton(java.lang.String text,
Node graphic)
Creates a new empty menu button with the given text and graphic to
display on the button.
|
MenuButton(java.lang.String text,
Node graphic,
MenuItem... items)
Creates a new menu button with the given text and graphic to
display on the button, and inserts the given items
into the
items list. |
Modifier and Type | Method and Description |
---|---|
protected Skin<?> |
createDefaultSkin()
Create a new instance of the default skin for this control.
|
void |
executeAccessibleAction(AccessibleAction action,
java.lang.Object... parameters) |
void |
fire()
This has no impact.
|
<any> |
getItems()
The items to show within this buttons menu.
|
<any> |
getOnHidden()
Gets the value of the property onHidden.
|
<any> |
getOnHiding()
Gets the value of the property onHiding.
|
<any> |
getOnShowing()
Gets the value of the property onShowing.
|
<any> |
getOnShown()
Gets the value of the property onShown.
|
Side |
getPopupSide()
Gets the value of the property popupSide.
|
void |
hide()
Hides the
ContextMenu . |
boolean |
isShowing()
Gets the value of the property showing.
|
<any> |
onHiddenProperty()
Called just after the
ContextMenu has been hidden. |
<any> |
onHidingProperty()
Called just prior to the
ContextMenu being hidden. |
<any> |
onShowingProperty()
Called just prior to the
ContextMenu being shown. |
<any> |
onShownProperty()
Called just after the
ContextMenu is shown. |
<any> |
popupSideProperty()
Indicates on which side the
ContextMenu should open in
relation to the MenuButton. |
void |
setOnHidden(<any> value)
Sets the value of the property onHidden.
|
void |
setOnHiding(<any> value)
Sets the value of the property onHiding.
|
void |
setOnShowing(<any> value)
Sets the value of the property onShowing.
|
void |
setOnShown(<any> value)
Sets the value of the property onShown.
|
void |
setPopupSide(Side value)
Sets the value of the property popupSide.
|
private void |
setShowing(boolean value) |
void |
show()
Shows the
ContextMenu , assuming this MenuButton is not disabled. |
ReadOnlyBooleanProperty |
showingProperty()
Indicates whether the
ContextMenu is currently visible. |
arm, armedProperty, disarm, getOnAction, isArmed, onActionProperty, setOnAction
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
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getControlChildren, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, loadSkinClass, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipProperty
public final ReadOnlyBooleanProperty showingProperty
ContextMenu
is currently visible.isShowing()
public final <any> popupSideProperty
ContextMenu
should open in
relation to the MenuButton. Menu items are generally laid
out vertically in either case.
For example, if the menu button were in a vertical toolbar on the left
edge of the application, you might change popupSide
to Side.RIGHT
so that the popup will appear to the right of the MenuButton.getPopupSide()
,
setPopupSide(Side)
public final <any> onShowingProperty
ContextMenu
being shown.getOnShowing()
,
#setOnShowing()
public final <any> onShownProperty
ContextMenu
is shown.getOnShown()
,
#setOnShown()
public final <any> onHidingProperty
ContextMenu
being hidden.getOnHiding()
,
#setOnHiding()
public final <any> onHiddenProperty
ContextMenu
has been hidden.getOnHidden()
,
#setOnHidden()
public static final <any> ON_SHOWING
public static final <any> ON_SHOWN
public static final <any> ON_HIDING
public static final <any> ON_HIDDEN
private final <any> items
private ReadOnlyBooleanWrapper showing
ContextMenu
is currently visible.private <any> popupSide
ContextMenu
should open in
relation to the MenuButton. Menu items are generally laid
out vertically in either case.
For example, if the menu button were in a vertical toolbar on the left
edge of the application, you might change popupSide
to Side.RIGHT
so that the popup will appear to the right of the MenuButton.private <any> onShowing
private <any> onShown
private <any> onHiding
private <any> onHidden
private static final java.lang.String DEFAULT_STYLE_CLASS
private static final PseudoClass PSEUDO_CLASS_OPENVERTICALLY
private static final PseudoClass PSEUDO_CLASS_SHOWING
public MenuButton()
Labeled.setText(String)
,
Labeled.setGraphic(Node)
and getItems()
to set the content.public MenuButton(java.lang.String text)
Labeled.setGraphic(Node)
and getItems()
to set the
content.text
- the text to display on the menu buttonpublic MenuButton(java.lang.String text, Node graphic)
getItems()
to set the content.text
- the text to display on the menu buttongraphic
- the graphic to display on the menu buttonpublic MenuButton(java.lang.String text, Node graphic, MenuItem... items)
items
list.text
- the text to display on the menu buttongraphic
- the graphic to display on the menu buttonitems
- The items to display in the popup menu.public final <any> getItems()
Commonly used controls include including MenuItem
,
CheckMenuItem
, RadioMenuItem
,
and of course Menu
, which if added to a menu, will become a sub
menu. SeparatorMenuItem
is another commonly used Node in the Menu's items
ObservableList.
private void setShowing(boolean value)
public final boolean isShowing()
public final ReadOnlyBooleanProperty showingProperty()
ContextMenu
is currently visible.isShowing()
public final void setPopupSide(Side value)
public final Side getPopupSide()
public final <any> popupSideProperty()
ContextMenu
should open in
relation to the MenuButton. Menu items are generally laid
out vertically in either case.
For example, if the menu button were in a vertical toolbar on the left
edge of the application, you might change popupSide
to Side.RIGHT
so that the popup will appear to the right of the MenuButton.getPopupSide()
,
setPopupSide(Side)
public final <any> onShowingProperty()
ContextMenu
being shown.getOnShowing()
,
#setOnShowing()
public final void setOnShowing(<any> value)
public final <any> getOnShowing()
public final <any> onShownProperty()
ContextMenu
is shown.getOnShown()
,
#setOnShown()
public final void setOnShown(<any> value)
public final <any> getOnShown()
public final <any> onHidingProperty()
ContextMenu
being hidden.getOnHiding()
,
#setOnHiding()
public final void setOnHiding(<any> value)
public final <any> getOnHiding()
public final <any> onHiddenProperty()
ContextMenu
has been hidden.getOnHidden()
,
#setOnHidden()
public final void setOnHidden(<any> value)
public final <any> getOnHidden()
public void show()
ContextMenu
, assuming this MenuButton is not disabled.#isDisabled()
,
isShowing()
public void hide()
ContextMenu
.isShowing()
public void fire()
fire
in class ButtonBase
protected Skin<?> createDefaultSkin()
-fx-skin
or set explicitly in a sub-class with setSkin(...)
.createDefaultSkin
in class Control
public void executeAccessibleAction(AccessibleAction action, java.lang.Object... parameters)
executeAccessibleAction
in class ButtonBase