- Type Parameters:
L
- The type of theJList
instance which will be managed by this builder.
JList
instances.
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 TypeMethodDescription_newBuilderWithState
(swingtree.BuilderState<L> newState) An internal wither method which creates a new builder instance with the providedBuilderState
stored inside it.protected swingtree.BuilderState
<L> _state()
Returns the state of the builder, which is a container for the wrapped component as well as it's type and currentEventProcessor
.onSelection
(sprouts.Action<ComponentDelegate<JList<E>, ListSelectionEvent>> action) Adds anAction
event handler to the underlyingJList
through aListSelectionListener
, which will be called when a list selection has been made.withCell
(Configurator<CellConf<L, V>> cellConfigurator) Allows for the configuration of a cell view for the items of theJList
instance.withCellRenderer
(ListCellRenderer<E> renderer) Sets theListCellRenderer
for theJList
, which renders the list items by supplying a custom component for each item through theListCellRenderer.getListCellRendererComponent(JList, Object, int, boolean, boolean)
method.withCells
(Configurator<CellBuilder<L, V>> renderBuilder) Use this to build a list cell renderer for various item types by defining a renderer for each type or usingObject
as a common type using the fluent builder API exposed to theConfigurator
lambda function passed to this method.withEntries
(E... entries) Takes the provided array of entry objects and sets them asJList
data.withEntries
(List<E> entries) Takes the provided list of entry objects and sets them asJList
data.withEntries
(sprouts.Vals<E> entries) Takes the provided observable property list of entries in the form of aVals
object and uses them as a basis for modelling theJList
data.withRenderComponent
(ListEntryRenderer<E, L> renderer) TheListEntryRenderer
passed to this method is a functional interface receiving aListEntryDelegate
instance and returns aJComponent
, which is used to render each entry of theJList
instance.withSelection
(sprouts.Val<E> selection) Takes an observable read-only property in the form of aVal
object and uses it as a basis for modelling theJList
selection.withSelection
(sprouts.Var<E> selection) Takes an observable property in the form of aVar
object and uses it as a basis for modelling theJList
selection.Methods inherited from class swingtree.UIForAnySwing
_addComponentTo, _addViewableProps, _addViewableProps, _isUndefinedColor, _isUndefinedFont, _setBackground, _setEnabled, _setMinHeight, _setMinWidth, _setPrefWidth, add, add, add, add, add, add, add, add, add, add, addAll, addAll, addAll, addAll, addAll, addAll, doUpdates, group, group, id, id, isEnabledIf, isEnabledIf, isEnabledIf, isEnabledIfNot, isEnabledIfNot, isEnabledIfNot, isFocusableIf, isFocusableIf, isFocusableIf, isFocusableIfNot, isFocusableIfNot, isFocusableIfNot, isValidIf, isVisibleIf, isVisibleIf, isVisibleIf, isVisibleIfNot, isVisibleIfNot, isVisibleIfNot, makeFocused, makeNonOpaque, makeOpaque, on, on, onCharTyped, onFocusGain, onFocusLoss, onHidden, onKeyPress, onKeyRelease, onKeyTyped, onMouseClick, onMouseDrag, onMouseEnter, onMouseEnter, onMouseEnterGreedy, onMouseExit, onMouseExit, onMouseExitGreedy, onMouseMove, onMousePress, onMouseRelease, onMouseWheelDown, onMouseWheelMove, onMouseWheelUp, onMoved, onPressed, onRelease, onResize, onShown, onTyped, onTyped, onView, withBackground, withBackground, withBackgroundColor, withBackgroundIf, withBackgroundIf, withBackgroundIf, withBackgroundIf, withBorder, withBorder, withBorderTitled, withBorderTitled, withBoxLayout, withCompoundBorder, withCompoundBorderTitled, withCursor, withCursor, withCursorIf, withCursorIf, withDragAway, withDropSite, withEmptyBorder, withEmptyBorder, withEmptyBorder, withEmptyBorder, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withEmptyBorderTitled, withFlowLayout, withFlowLayout, withFlowLayout, withForeground, withForeground, withForegroundColor, withForegroundIf, withForegroundIf, withForegroundIf, withForegroundIf, withGridBagLayout, withGridLayout, withGridLayout, withGridLayout, withHeight, withHeight, withHeightExactly, withHeightExactly, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLayout, withLineBorder, withLineBorder, withLineBorder, withLineBorderTitled, withLineBorderTitled, withLineBorderTitled, withLineBorderTitled, withMatteBorder, withMatteBorder, withMatteBorder, withMatteBorderTitled, withMatteBorderTitled, withMatteBorderTitled, withMaxHeight, withMaxHeight, withMaxSize, withMaxSize, withMaxSize, withMaxSize, withMaxSize, withMaxWidth, withMaxWidth, withMinHeight, withMinHeight, withMinSize, withMinSize, withMinSize, withMinSize, withMinSize, withMinWidth, withMinWidth, withPrefHeight, withPrefHeight, withPrefSize, withPrefSize, withPrefSize, withPrefSize, withPrefSize, withPrefWidth, withPrefWidth, withProperty, withRepaintOn, withRepaintOn, withRepaintOn, withRepaintOn, withRepaintOn, withRepaintOn, withRoundedLineBorder, withRoundedLineBorder, withRoundedLineBorder, withRoundedLineBorder, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withRoundedLineBorderTitled, withSize, withSize, withSize, withSize, withSizeExactly, withSizeExactly, withSizeExactly, withSizeExactly, withStyle, withTooltip, withTooltip, withTransitionalStyle, withTransitoryStyle, withWidth, withWidth, withWidthExactly, withWidthExactly
Methods inherited from class swingtree.UIForAnything
_addBuildersTo, _addBuilderTo, _addComponentsTo, _disposeState, _onShow, _onShow, _runInApp, _runInApp, _runInUI, _this, _with, _withOnShow, _withOnShow, add, add, add, add, apply, applyIf, applyIfPresent, component, equals, get, getComponent, getType, hashCode, peek, toString
-
Method Details
-
_state
Description copied from class:UIForAnything
Returns the state of the builder, which is a container for the wrapped component as well as it's type and currentEventProcessor
. -
_newBuilderWithState
Description copied from class:UIForAnything
An internal wither method which creates a new builder instance with the providedBuilderState
stored inside it.- Specified by:
_newBuilderWithState
in classUIForAnything<UIForList<E,
L extends JList<E>>, L extends JList<E>, JComponent> - Parameters:
newState
- The new state which should be stored inside the new builder instance.- Returns:
- A new builder instance with the provided state stored inside it.
-
withEntries
Takes the provided list of entry objects and sets them asJList
data.- Parameters:
entries
- The list of entries to set as data.- Returns:
- This instance of the builder node.
-
withEntries
Takes the provided array of entry objects and sets them asJList
data.- Parameters:
entries
- The array of entries to set as data.- Returns:
- This instance of the builder node.
-
withEntries
Takes the provided observable property list of entries in the form of aVals
object and uses them as a basis for modelling theJList
data. If theVals
object changes, theJList
data will be updated accordingly, and vice versa.- Parameters:
entries
- TheVals
of entries to set as data model.- Returns:
- This instance of the builder node to allow for builder-style fluent method chaining.
-
withSelection
Takes an observable property in the form of aVar
object and uses it as a basis for modelling theJList
selection. If theVar
object changes, theJList
selection will be updated accordingly, and vice versa. If you do not want this relationship to be bidirectional, usewithSelection(Val)
instead.- Parameters:
selection
- TheVar
of entries to set as selection model.- Returns:
- This instance of the builder node to allow for fluent method chaining.
-
withSelection
Takes an observable read-only property in the form of aVal
object and uses it as a basis for modelling theJList
selection. If theVal
object changes, theJList
selection will be updated accordingly. However, if theJList
selection changes due to user interaction, theVal
object will not be updated.- Parameters:
selection
- TheVal
of entries to set as selection model.- Returns:
- This instance of the builder node to allow for fluent method chaining.
-
withRenderComponent
TheListEntryRenderer
passed to this method is a functional interface receiving aListEntryDelegate
instance and returns aJComponent
, which is used to render each entry of theJList
instance.
A typical usage of this method would look like this:listOf(vm.colors()) .withRenderComponent( it -> new Component() { {@literal @}Override public void paint(Graphics g) { g.setColor(it.entry().orElse(Color.PINK)); g.fillRect(0,0,getWidth(),getHeight()); } })
In this example, a new
JList
is created for the observable property list of colors, which is provided by thevm.colors()
method. The entries of said list are individually exposed specified renderer lambda expression, which return aJComponent
instance that is used by theJList
to render each entry. In this case a colored rectangle is rendered for each entry.Note that the preferred way to build a list cell renderer for various item types is to use the
withCell(Configurator)
method, which provides a more rich and fluent builder API.- Parameters:
renderer
- TheListEntryRenderer
that will be used to supplyJComponent
s responsible for rendering each entry of theJList
instance.- Returns:
- This instance of the builder node to allow for fluent method chaining.
-
onSelection
public final UIForList<E,L> onSelection(sprouts.Action<ComponentDelegate<JList<E>, ListSelectionEvent>> action) Adds anAction
event handler to the underlyingJList
through aListSelectionListener
, which will be called when a list selection has been made. {see JList#addListSelectionListener(ListSelectionListener)}.- Parameters:
action
- TheAction
that will be notified.- Returns:
- This very instance, which enables builder-style method chaining.
-
withCellRenderer
Sets theListCellRenderer
for theJList
, which renders the list items by supplying a custom component for each item through theListCellRenderer.getListCellRendererComponent(JList, Object, int, boolean, boolean)
method.Also see
withCells(Configurator)
method, which is the preferred way to build a list cell renderer for various item types using a more rich and fluent builder API.- Parameters:
renderer
- TheListCellRenderer
that will be used to paint each cell in the list.- Returns:
- This very instance, which enables builder-style method chaining.
-
withCells
Use this to build a list cell renderer for various item types by defining a renderer for each type or usingObject
as a common type using the fluent builder API exposed to theConfigurator
lambda function passed to this method.
This method is typically used when the list holds inhomogeneous item types which you want to be handled differently in the list view.
Note that a similar API is also available for theUI.list(new Object[]{":-)", 42L, 'ยง'}) .withCells( it -> it .when(String.class).asText( cell -> "String: "+cell.getValue() ) .when(Character.class).asText( cell -> "Char: "+cell.getValue() ) .when(Number.class).asText( cell -> "Number: "+cell.getValue() ) );
JComboBox
andJTable
components, seeUIForCombo.withCells(Configurator)
,UIForTable.withCells(Configurator)
andUIForTable.withCellsForColumn(int, Configurator)
for more information.Also see
withCell(Configurator)
method, which constitutes the preferred way to build a list cell renderer as it is simpler, more concise and less error-prone.- Type Parameters:
V
- The type of the value that is being rendered in this combo box.- Parameters:
renderBuilder
- A lambda function that configures the renderer for this combo box.- Returns:
- This combo box instance for further configuration.
-
withCell
Allows for the configuration of a cell view for the items of theJList
instance. TheConfigurator
lambda function passed to this method receives aCellConf
exposing the current item value and the current selection state of the cell. You may update return an updated cell with a desired view component through methods likeCellConf.view(Component)
orCellConf.updateView(Configurator)
.Here code snippet demonstrating how this method may be used as part of a UI declaration:
In this example, a newUI.list(new Month[]{Month.JANUARY, Month.FEBRUARY, Month.MARCH}) .withCell( cell -> cell .updateView( comp -> comp .orGet(JLabel::new) // initialize a new JLabel if not already present .updateIf(JLabel.class, tf -> { tf.setText(cell.valueAsString().orElse("")); tf.setBackground(cell.isSelected() ? Color.YELLOW : Color.WHITE); return tf; }) ) )
JList
is created for an array of objects. TheConfigurator
lambda function passed to thewithCell(Configurator)
method configures the cell view for each item in the list.- Type Parameters:
V
- The type of the value that is being rendered in this combo box.- Parameters:
cellConfigurator
- TheConfigurator
lambda function that configures the cell view.- Returns:
- This instance of the builder node to allow for fluent method chaining.
-