public class ActionGroup extends Action
Action
instances, allowing for more complex controls like ToolBar,
MenuBar and ContextMenu to be automatically generated from
the collection of actions inside the ActionGroup. For your convenience,
there are a number of utility methods that do precisely this in the
ActionUtils class.
Consider the following code example (note that DummyAction is a fake class
that extends from (and implements) Action):
// Firstly, create a list of Actions
Collection<? extends Action> actions = Arrays.asList(
new ActionGroup("Group 1", new DummyAction("Action 1.1"),
new DummyAction("Action 2.1") ),
new ActionGroup("Group 2", new DummyAction("Action 2.1"),
new ActionGroup("Action 2.2", new DummyAction("Action 2.2.1"),
new DummyAction("Action 2.2.2")),
new DummyAction("Action 2.3") ),
new ActionGroup("Group 3", new DummyAction("Action 3.1"),
new DummyAction("Action 3.2") )
);
// Use the ActionUtils class to create UI controls from these actions, e.g:
MenuBar menuBar = ActionUtils.createMenuBar(actions);
ToolBar toolBar = ActionUtils.createToolBar(actions);
Label context = new Label("Right-click to see the context menu");
context.setContextMenu(ActionUtils.createContextMenu(actions));
The end result of running the code above is shown in the screenshots below (hopefully it goes without saying that within the 'Group 1', 'Group 2' and 'Group 3' options are the 'Action 1.1', etc actions that have been specified in the code above):
| MenuBar: | ![]() |
| ToolBar: | ![]() |
| ContextMenu: | ![]() |
Action,
ActionUtils| Constructor and Description |
|---|
ActionGroup(java.lang.String text,
Action... actions)
Creates an ActionGroup with the given text as the name of the
Action,
and zero or more Actions as members of this ActionGroup. |
ActionGroup(java.lang.String text,
java.util.Collection<Action> actions)
Creates an ActionGroup with the given text as the name of the
Action,
and collection of Actions as members of this ActionGroup. |
ActionGroup(java.lang.String text,
javafx.scene.Node icon,
Action... actions)
Creates an ActionGroup with the given text as the name of the
Action,
and zero or more Actions as members of this ActionGroup. |
ActionGroup(java.lang.String text,
javafx.scene.Node icon,
java.util.Collection<Action> actions)
Creates an ActionGroup with the given text as the name of the
Action,
and collection of Actions as members of this ActionGroup. |
| Modifier and Type | Method and Description |
|---|---|
javafx.collections.ObservableList<Action> |
getActions()
The list of
Action instances that exist within this ActionGroup. |
java.lang.String |
toString() |
acceleratorProperty, disabledProperty, getAccelerator, getEventHandler, getGraphic, getLongText, getProperties, getStyle, getStyleClass, getText, graphicProperty, handle, isDisabled, isSelected, lock, longTextProperty, selectedProperty, setAccelerator, setDisabled, setEventHandler, setGraphic, setLongText, setSelected, setStyle, setText, styleProperty, textPropertypublic ActionGroup(java.lang.String text,
Action... actions)
public ActionGroup(java.lang.String text,
java.util.Collection<Action> actions)
Action,
and collection of Actions as members of this ActionGroup.public ActionGroup(java.lang.String text,
javafx.scene.Node icon,
Action... actions)
public final javafx.collections.ObservableList<Action> getActions()
Action instances that exist within this ActionGroup.
This list may be modified, as shown in the class documentation.public java.lang.String toString()
toString in class java.lang.Object