java.lang.Object
swingtree.SplitItem<I>
- Type Parameters:
I- The type of the item which will be passed to theActions.
An immutable data carrier exposing everything needed to configure an item of a
JSplitButton.
SplitItems 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 thisSplitItemis enabled or not based on the value of the provided observable boolean property.of(I item) A factory method to create aSplitItemfor aJSplitButtonfrom a simple text string which will be displayed on theSplitItemwhen it is part of a clickedJSplitButton.A factory method to create aSplitItemfor aJSplitButtonfrom aValproperty 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 theJSplitButtonis being pressed and thisSplitItemwas selected to be the primary button.onSelection(sprouts.Action<SplitItemDelegate<I>> action) Use this to perform some action when the user selects aSplitItemamong all other split button items.
-
Method Details
-
of
A factory method to create aSplitItemfor aJSplitButtonfrom a simple text string which will be displayed on theSplitItemwhen it is part of a clickedJSplitButton. -
of
A factory method to create aSplitItemfor aJSplitButtonfrom aValproperty 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- TheJMenuItemsubtype for which aSplitItem(forJSplitButton) should be created.- Returns:
- A
SplitItemwrapping the providedJMenuItemtype.
-
of
Use this to create aSplitItemfor aJSplitButtonfrom aUIForMenuItemUI declaration. This is useful when you want to create aSplitItemfrom aJMenuItemwhich 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 theJSplitButtonis being pressed and thisSplitItemwas 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 theJSplitButtonis being pressed and thisSplitItemwas selected.- Returns:
- An immutable copy of this with the provided lambda set.
-
onSelection
Use this to perform some action when the user selects aSplitItemamong all other split button items. A common use case would be to set the text of theJSplitButtonby 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 aSplitItemDelegateinstance.- Returns:
- An immutable copy of this with the provided lambda set.
-
isEnabledIf
Dynamically determines whether thisSplitItemis 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 thisSplitItemwill change accordingly. This is done by callingJMenuItem.setEnabled(boolean)on the underlyingJMenuItemwith the value of the property.
-