Top Description Fields Constructors Methods
javafx.scene.control

public Class MenuButton

extends ButtonBase
Class Inheritance
Known Direct Subclasses
javafx.scene.control.SplitMenuButton, com.sun.javafx.scene.control.MenuBarButton
Imports
javafx.beans.property.ObjectProperty, .ObjectPropertyBase, .ReadOnlyBooleanProperty, .ReadOnlyBooleanWrapper, javafx.collections.FXCollections, .ObservableList, javafx.css.PseudoClass, javafx.event.ActionEvent, .Event, .EventHandler, .EventType, javafx.geometry.Side, javafx.scene.AccessibleAction, .AccessibleRole, .Node, javafx.scene.control.skin.MenuButtonSkin, com.sun.javafx.tk.Toolkit

MenuButton is a button which, when clicked or pressed, will show a 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"));
Image of the MenuButton control

MnemonicParsing is enabled by default for MenuButton.

Since
JavaFX 2.0
See Also
MenuItem, Menu, SplitMenuButton

Field Summary

Modifier and TypeField and Description
private static final String
private final ObservableList<MenuItem>
public static final EventType<Event>
ON_HIDDEN

Called when the MenuButton popup has been hidden.

public static final EventType<Event>
ON_HIDING

Called when the MenuButton popup will be hidden.

public static final EventType<Event>
ON_SHOWING

Called prior to the MenuButton showing its popup after the user has clicked or otherwise interacted with the MenuButton.

public static final EventType<Event>
ON_SHOWN

Called after the MenuButton has shown its popup.

private ObjectProperty<EventHandler<Event>>
private ObjectProperty<EventHandler<Event>>
private ObjectProperty<EventHandler<Event>>
private ObjectProperty<EventHandler<Event>>
private ObjectProperty<Side>
popupSide

Indicates on which side the ContextMenu should open in relation to the MenuButton.

private static final PseudoClass
private static final PseudoClass
private ReadOnlyBooleanWrapper
showing

Indicates whether the ContextMenu is currently visible.

Constructor Summary

AccessConstructor and Description

Method Summary

Modifier and TypeMethod and Description
protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

public void
executeAccessibleAction(AccessibleAction action, Object... parameters)

Overrides javafx.scene.control.ButtonBase.executeAccessibleAction.

This method is called by the assistive technology to request the action indicated by the argument should be executed.

public void
fire()

Implements abstract javafx.scene.control.ButtonBase.fire.

This has no impact.

public final ObservableList<MenuItem>

Returns:

the list of menu items within this buttons menu
getItems
()

The items to show within this buttons menu.

public final EventHandler<Event>
public final EventHandler<Event>
public final EventHandler<Event>
public final EventHandler<Event>
public final Side
public void
hide()

Hides the ContextMenu.

public final boolean
public final ObjectProperty<EventHandler<Event>>

Returns:

the on hidden property
onHiddenProperty
()

Called just after the ContextMenu has been hidden.

public final ObjectProperty<EventHandler<Event>>

Returns:

the on hiding property
onHidingProperty
()

Called just prior to the ContextMenu being hidden.

public final ObjectProperty<EventHandler<Event>>

Returns:

the on showing property
onShowingProperty
()

Called just prior to the ContextMenu being shown.

public final ObjectProperty<EventHandler<Event>>

Returns:

the on shown property
onShownProperty
()

Called just after the ContextMenu is shown.

public final ObjectProperty<Side>
public final void
public final void
public final void
public final void
public final void
private void
setShowing(boolean value)

public void
show()

Shows the ContextMenu, assuming this MenuButton is not disabled.

public final ReadOnlyBooleanProperty
Inherited from javafx.scene.control.ButtonBase:
armarmedPropertydisarmgetOnActionisArmedonActionPropertysetOnAction

Field Detail

DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS
itemsback to summary
private final ObservableList<MenuItem> items
ON_HIDDENback to summary
public static final EventType<Event> ON_HIDDEN

Called when the MenuButton popup has been hidden.

Since
JavaFX 8u60
ON_HIDINGback to summary
public static final EventType<Event> ON_HIDING

Called when the MenuButton popup will be hidden.

Since
JavaFX 8u60
ON_SHOWINGback to summary
public static final EventType<Event> ON_SHOWING

Called prior to the MenuButton showing its popup after the user has clicked or otherwise interacted with the MenuButton.

Since
JavaFX 8u60
ON_SHOWNback to summary
public static final EventType<Event> ON_SHOWN

Called after the MenuButton has shown its popup.

Since
JavaFX 8u60
onHiddenback to summary
private ObjectProperty<EventHandler<Event>> onHidden
onHidingback to summary
private ObjectProperty<EventHandler<Event>> onHiding
onShowingback to summary
private ObjectProperty<EventHandler<Event>> onShowing
onShownback to summary
private ObjectProperty<EventHandler<Event>> onShown
popupSideback to summary
private ObjectProperty<Side> popupSide

Indicates on which side the 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.

Default Value
Side.BOTTOM
PSEUDO_CLASS_OPENVERTICALLYback to summary
private static final PseudoClass PSEUDO_CLASS_OPENVERTICALLY
PSEUDO_CLASS_SHOWINGback to summary
private static final PseudoClass PSEUDO_CLASS_SHOWING
showingback to summary
private ReadOnlyBooleanWrapper showing

Indicates whether the ContextMenu is currently visible.

Constructor Detail

Method Detail

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.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-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
executeAccessibleActionback to summary
public void executeAccessibleAction(AccessibleAction action, Object... parameters)

Overrides javafx.scene.control.ButtonBase.executeAccessibleAction.

Doc from javafx.scene.control.ButtonBase.executeAccessibleAction.

This method is called by the assistive technology to request the action indicated by the argument should be executed.

This method is commonly overridden by subclasses to implement action that are required for a specific role.
If a particular action is not handled, the superclass implementation must be called.

Annotations
@Override
fireback to summary
public void fire()

Implements abstract javafx.scene.control.ButtonBase.fire.

This has no impact.

Annotations
@Override
getItemsback to summary
public final ObservableList<MenuItem> getItems()

The items to show within this buttons menu. If this ObservableList is modified at runtime, the Menu will update as expected.

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.

Returns:ObservableList<MenuItem>

the list of menu items within this buttons menu

getOnHiddenback to summary
public final EventHandler<Event> getOnHidden()
getOnHidingback to summary
public final EventHandler<Event> getOnHiding()
getOnShowingback to summary
public final EventHandler<Event> getOnShowing()
getOnShownback to summary
public final EventHandler<Event> getOnShown()
getPopupSideback to summary
public final Side getPopupSide()
hideback to summary
public void hide()

Hides the ContextMenu.

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
See Also
isShowing()
isShowingback to summary
public final boolean isShowing()
onHiddenPropertyback to summary
public final ObjectProperty<EventHandler<Event>> onHiddenProperty()

Called just after the ContextMenu has been hidden.

Returns:ObjectProperty<EventHandler<Event>>

the on hidden property

Since
10
onHidingPropertyback to summary
public final ObjectProperty<EventHandler<Event>> onHidingProperty()

Called just prior to the ContextMenu being hidden.

Returns:ObjectProperty<EventHandler<Event>>

the on hiding property

Since
10
onShowingPropertyback to summary
public final ObjectProperty<EventHandler<Event>> onShowingProperty()

Called just prior to the ContextMenu being shown.

Returns:ObjectProperty<EventHandler<Event>>

the on showing property

Since
10
onShownPropertyback to summary
public final ObjectProperty<EventHandler<Event>> onShownProperty()

Called just after the ContextMenu is shown.

Returns:ObjectProperty<EventHandler<Event>>

the on shown property

Since
10
popupSidePropertyback to summary
public final ObjectProperty<Side> popupSideProperty()
setOnHiddenback to summary
public final void setOnHidden(EventHandler<Event> value)
setOnHidingback to summary
public final void setOnHiding(EventHandler<Event> value)
setOnShowingback to summary
public final void setOnShowing(EventHandler<Event> value)
setOnShownback to summary
public final void setOnShown(EventHandler<Event> value)
setPopupSideback to summary
public final void setPopupSide(Side value)
setShowingback to summary
private void setShowing(boolean value)
showback to summary
public void show()

Shows the ContextMenu, assuming this MenuButton is not disabled.

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
See Also
isDisabled(), isShowing()
showingPropertyback to summary
public final ReadOnlyBooleanProperty showingProperty()