java.lang.Object
swingtree.SplitItem<I>
- Type Parameters:
I
- The type of the item which will be passed to theAction
s.
An immutable data carrier exposing everything needed to configure an item of a
JSplitButton
.
SplitItem
s will be turned into button options for the JSplitButton
which can be supplied to a split button through the builder API exposed by UIForSplitButton
like so:
UI.splitButton("Hey!")
.add(UI.splitItem("first"))
.add(UI.splitItem("second").onClick( it -> ... ))
.add(UI.splitItem("third").onClick( it -> ... ).onSelected( it -> ... ))
For more information, please take a look at the living swing-tree documentation where you can browse a large collection of examples demonstrating how to use the API of this class.
-
Method Summary
Modifier and TypeMethodDescriptionisEnabledIf
(sprouts.Var<Boolean> isEnabled) Dynamically determines whether thisSplitItem
is enabled or not based on the value of the provided observable boolean property.of
(I item) A factory method to create aSplitItem
for aJSplitButton
from a simple text string which will be displayed on theSplitItem
when it is part of a clickedJSplitButton
.A factory method to create aSplitItem
for aJSplitButton
from aVal
property which will be used to dynamically determine the text displayed on theSplitItem
.of
(UIForMenuItem<M> item) onButtonClick
(sprouts.Action<SplitItemDelegate<I>> action) Use this to register an action which will be called when theJSplitButton
is being pressed and thisSplitItem
was selected to be the primary button.onSelection
(sprouts.Action<SplitItemDelegate<I>> action) Use this to perform some action when the user selects aSplitItem
among all other split button items.
-
Method Details
-
of
A factory method to create aSplitItem
for aJSplitButton
from a simple text string which will be displayed on theSplitItem
when it is part of a clickedJSplitButton
. -
of
A factory method to create aSplitItem
for aJSplitButton
from aVal
property which will be used to dynamically determine the text displayed on theSplitItem
. -
of
- Type Parameters:
I
- The type parameter for the provided item type.- Parameters:
item
- TheJMenuItem
subtype for which aSplitItem
(forJSplitButton
) should be created.- Returns:
- A
SplitItem
wrapping the providedJMenuItem
type.
-
of
Use this to create aSplitItem
for aJSplitButton
from aUIForMenuItem
UI declaration. This is useful when you want to create aSplitItem
from aJMenuItem
which is configured using the declarative UI builder API exposed byUIForMenuItem
. SeeUIFactoryMethods.menuItem()
for more information. -
makeSelected
- Returns:
- An immutable copy of this with the provided text set.
-
onButtonClick
Use this to register an action which will be called when theJSplitButton
is being pressed and thisSplitItem
was selected to be the primary button.UI.splitButton("Hey!") .add(UI.splitItem("load")) .add(UI.splitItem("save").onClick( it -> doSaving() )) .add(UI.splitItem("delete"))
- Parameters:
action
- The action lambda which will be called when theJSplitButton
is being pressed and thisSplitItem
was selected.- Returns:
- An immutable copy of this with the provided lambda set.
-
onSelection
Use this to perform some action when the user selects aSplitItem
among all other split button items. A common use case would be to set the text of theJSplitButton
by calling theSplitItemDelegate.getSplitButton()
method on the context object supplied to the provided action lambda like so:UI.splitButton("Hey!") .add(UI.splitItem("first")) .add(UI.splitItem("second").onSelected( it -> it.getSplitButton().setText("Hey hey!") )) .add(UI.splitItem("third"))
- Parameters:
action
- The action which will be called when the button was selected and which will receive some context information in the form of aSplitItemDelegate
instance.- Returns:
- An immutable copy of this with the provided lambda set.
-
isEnabledIf
Dynamically determines whether thisSplitItem
is enabled or not based on the value of the provided observable boolean property. This means that whenever the value of the property changes, the enabled state of thisSplitItem
will change accordingly. This is done by callingJMenuItem.setEnabled(boolean)
on the underlyingJMenuItem
with the value of the property.
-