Spec-Zone .ru
спецификации, руководства, описания, API
|
public class MenuItem extends java.lang.Object implements EventTarget
MenuItem is intended to be used in conjunction with Menu
to provide
options to users. MenuItem serves as the base class for the bulk of JavaFX menus
API.
It has a display text
property, as well as an optional graphic
node
that can be set on it.
The accelerator
property enables accessing the
associated action in one keystroke. Also, as with the Button
control,
by using the setOnAction(javafx.event.EventHandler)
method, you can have an instance of MenuItem
perform any action you wish.
Note: Whilst any size of graphic can be inserted into a MenuItem, the most commonly used size in most applications is 16x16 pixels. This is the recommended graphic dimension to use if you're using the default style provided by JavaFX.
To create a MenuItem is simple:
MenuItem menuItem = new MenuItem("Open");
menuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
System.out.println("Opening Database Connection...");
}
});
menuItem.setGraphic(new ImageView("path to image"));
Refer to the Menu
page to learn how to insert MenuItem into a menu
instance. Briefly however, you can insert the MenuItem from the previous
example into a Menu as such:
final Menu menu1 = new Menu("File");
menu.getitems().add(menuItem);
Menu
Type | Property and Description |
---|---|
ObjectProperty<KeyCombination> |
accelerator |
BooleanProperty |
disable |
ObjectProperty<Node> |
graphic |
StringProperty |
id
*
Properties *
*
|
BooleanProperty |
mnemonicParsing
MnemonicParsing property to enable/disable text parsing.
|
ObjectProperty<EventHandler<ActionEvent>> |
onAction |
ReadOnlyObjectProperty<Menu> |
parentMenu |
ReadOnlyObjectProperty<ContextMenu> |
parentPopup |
StringProperty |
style |
StringProperty |
text |
BooleanProperty |
visible |
Constructor and Description |
---|
MenuItem()
*
Constructors *
*
|
MenuItem(java.lang.String text)
Constructs a MenuItem and sets the display text with the specified text
|
MenuItem(java.lang.String text,
Node graphic)
Constructor s MenuItem and sets the display text with the specified text
and sets the graphic
Node to the given node. |
Modifier and Type | Method and Description |
---|---|
ObjectProperty<KeyCombination> |
acceleratorProperty() |
<E extends Event> |
addEventHandler(EventType<E> eventType,
EventHandler<E> eventHandler)
Registers an event handler to this MenuItem.
|
EventDispatchChain |
buildEventDispatchChain(EventDispatchChain tail)
Construct an event dispatch chain for this target.
|
BooleanProperty |
disableProperty() |
void |
fire()
Fires a new ActionEvent.
|
KeyCombination |
getAccelerator() |
Node |
getGraphic() |
java.lang.String |
getId()
*
Properties *
*
|
EventHandler<ActionEvent> |
getOnAction() |
Menu |
getParentMenu() |
ContextMenu |
getParentPopup() |
ObservableMap<java.lang.Object,java.lang.Object> |
getProperties()
Returns an observable map of properties on this menu item for use primarily
by application developers.
|
java.lang.String |
getStyle() |
ObservableList<java.lang.String> |
getStyleClass()
*
Public API *
*
|
java.lang.String |
getText() |
java.lang.Object |
getUserData()
Returns a previously set Object property, or null if no such property
has been set using the
setUserData(java.lang.Object) method. |
ObjectProperty<Node> |
graphicProperty() |
StringProperty |
idProperty()
*
Properties *
*
|
boolean |
isDisable() |
boolean |
isMnemonicParsing()
MnemonicParsing property to enable/disable text parsing.
|
boolean |
isVisible() |
BooleanProperty |
mnemonicParsingProperty()
MnemonicParsing property to enable/disable text parsing.
|
ObjectProperty<EventHandler<ActionEvent>> |
onActionProperty() |
ReadOnlyObjectProperty<Menu> |
parentMenuProperty() |
ReadOnlyObjectProperty<ContextMenu> |
parentPopupProperty() |
<E extends Event> |
removeEventHandler(EventType<E> eventType,
EventHandler<E> eventHandler)
Unregisters a previously registered event handler from this MenuItem.
|
void |
setAccelerator(KeyCombination value) |
void |
setDisable(boolean value) |
void |
setGraphic(Node value)
An optional graphic for the
MenuItem . |
void |
setId(java.lang.String value)
*
Properties *
*
|
void |
setMnemonicParsing(boolean value)
MnemonicParsing property to enable/disable text parsing.
|
void |
setOnAction(EventHandler<ActionEvent> value)
The action, which is invoked whenever the MenuItem is fired.
|
protected void |
setParentMenu(Menu value)
This is the
Menu in which this MenuItem exists. |
protected void |
setParentPopup(ContextMenu value)
This is the
ContextMenu in which this MenuItem exists. |
void |
setStyle(java.lang.String value) |
void |
setText(java.lang.String value)
The text to display in the
MenuItem . |
void |
setUserData(java.lang.Object value)
Convenience method for setting a single Object property that can be
retrieved at a later date.
|
void |
setVisible(boolean value) |
StringProperty |
styleProperty() |
StringProperty |
textProperty() |
BooleanProperty |
visibleProperty() |
getId()
,
setId(String)
getStyle()
,
setStyle(String)
getParentMenu()
,
setParentMenu(Menu)
getParentPopup()
,
setParentPopup(ContextMenu)
getText()
,
setText(String)
getGraphic()
,
setGraphic(Node)
getOnAction()
,
setOnAction(EventHandler)
isDisable()
,
setDisable(boolean)
isVisible()
,
setVisible(boolean)
The default value for MenuItem is true.
public MenuItem()
public MenuItem(java.lang.String text)
setText(java.lang.String)
public final void setId(java.lang.String value)
public final java.lang.String getId()
public final StringProperty idProperty()
getId()
,
setId(String)
public final void setStyle(java.lang.String value)
public final java.lang.String getStyle()
public final StringProperty styleProperty()
getStyle()
,
setStyle(String)
protected final void setParentMenu(Menu value)
Menu
in which this MenuItem
exists. It is
possible for an instance of this class to not have a parentMenu
-
this means that this instance is either:
parentMenu
.
Menu
(i.e. it is a context menu, attached directly to a
MenuBar
, MenuButton
, or any of the other controls that use
Menu
internally.
public final Menu getParentMenu()
public final ReadOnlyObjectProperty<Menu> parentMenuProperty()
getParentMenu()
,
setParentMenu(Menu)
protected final void setParentPopup(ContextMenu value)
ContextMenu
in which this MenuItem
exists.public final ContextMenu getParentPopup()
public final ReadOnlyObjectProperty<ContextMenu> parentPopupProperty()
getParentPopup()
,
setParentPopup(ContextMenu)
public final void setText(java.lang.String value)
MenuItem
.public final java.lang.String getText()
public final StringProperty textProperty()
getText()
,
setText(String)
public final void setGraphic(Node value)
MenuItem
. This will normally be
an ImageView
node, but there is no requirement for this to be
the case.public final Node getGraphic()
public final ObjectProperty<Node> graphicProperty()
getGraphic()
,
setGraphic(Node)
public final void setOnAction(EventHandler<ActionEvent> value)
fire()
method.public final EventHandler<ActionEvent> getOnAction()
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty()
getOnAction()
,
setOnAction(EventHandler)
public final void setDisable(boolean value)
public final boolean isDisable()
public final BooleanProperty disableProperty()
isDisable()
,
setDisable(boolean)
public final void setVisible(boolean value)
public final boolean isVisible()
public final BooleanProperty visibleProperty()
isVisible()
,
setVisible(boolean)
public final void setAccelerator(KeyCombination value)
public final KeyCombination getAccelerator()
public final ObjectProperty<KeyCombination> acceleratorProperty()
public final void setMnemonicParsing(boolean value)
The default value for MenuItem is true.
public final boolean isMnemonicParsing()
The default value for MenuItem is true.
public final BooleanProperty mnemonicParsingProperty()
The default value for MenuItem is true.
public ObservableList<java.lang.String> getStyleClass()
public void fire()
public <E extends Event> void addEventHandler(EventType<E> eventType, EventHandler<E> eventHandler)
Event
of the specified type during the bubbling
phase of event delivery.E
- the specific event class of the handlereventType
- the type of the events to receive by the handlereventHandler
- the handler to registerpublic <E extends Event> void removeEventHandler(EventType<E> eventType, EventHandler<E> eventHandler)
E
- the specific event class of the handlereventType
- the event type from which to unregistereventHandler
- the handler to unregisterpublic EventDispatchChain buildEventDispatchChain(EventDispatchChain tail)
EventTarget
. This event target is
not automatically added to the chain, so if it wants to process events,
it needs to add an EventDispatcher
for itself to the chain.
In the case the event target is part of some hierarchy, the chain for it is usually built from event dispatchers collected from the root of the hierarchy to the event target.
The event dispatch chain is constructed by modifications to the provided initial event dispatch chain. The returned chain should have the initial chain at its end so the dispatchers should be prepended to the initial chain.
The caller shouldn't assume that the initial chain remains unchanged nor that the returned value will reference a different chain.
buildEventDispatchChain
in interface EventTarget
tail
- the initial chain to build frompublic java.lang.Object getUserData()
setUserData(java.lang.Object)
method.public void setUserData(java.lang.Object value)
Node.getUserData()
.value
- The value to be stored - this can later be retrieved by calling
Node.getUserData()
.public ObservableMap<java.lang.Object,java.lang.Object> getProperties()
Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. Use is subject to