- Type Parameters:
L- The type of theJListinstance 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 providedBuilderStatestored 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 anActionevent handler to the underlyingJListthrough 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 theJListinstance.withCellRenderer(ListCellRenderer<E> renderer) Sets theListCellRendererfor 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 usingObjectas a common type using the fluent builder API exposed to theConfiguratorlambda function passed to this method.withEntries(E... entries) Takes the provided array of entry objects and sets them asJListdata.withEntries(List<E> entries) Takes the provided list of entry objects and sets them asJListdata.withEntries(sprouts.Vals<E> entries) Takes the provided observable property list of entries in the form of aValsobject and uses them as a basis for modelling theJListdata.withRenderComponent(ListEntryRenderer<E, L> renderer) TheListEntryRendererpassed to this method is a functional interface receiving aListEntryDelegateinstance and returns aJComponent, which is used to render each entry of theJListinstance.withSelection(sprouts.Val<E> selection) Takes an observable read-only property in the form of aValobject and uses it as a basis for modelling theJListselection.withSelection(sprouts.Var<E> selection) Takes an observable property in the form of aVarobject and uses it as a basis for modelling theJListselection.Methods inherited from class swingtree.UIForAnySwing
_addComponentTo, _addViewableProps, _addViewableProps, _addViewableProps, _isUndefinedColor, _isUndefinedFont, _setBackground, _setEnabled, _setMinHeight, _setMinWidth, _setPrefWidth, _tryCalculatingDiffBetween, add, add, add, add, add, add, add, add, add, add, addAll, addAll, addAll, 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, withWidthExactlyMethods inherited from class swingtree.UIForAnything
_addBuildersTo, _addBuilderTo, _addComponentsTo, _disposeState, _onShow, _onShow, _onShowDelegated, _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:UIForAnythingReturns 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:UIForAnythingAn internal wither method which creates a new builder instance with the providedBuilderStatestored inside it.- Specified by:
_newBuilderWithStatein 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 asJListdata.- 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 asJListdata.- 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 aValsobject and uses them as a basis for modelling theJListdata. If theValsobject changes, theJListdata will be updated accordingly, and vice versa.- Parameters:
entries- TheValsof 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 aVarobject and uses it as a basis for modelling theJListselection. If theVarobject changes, theJListselection will be updated accordingly, and vice versa. If you do not want this relationship to be bidirectional, usewithSelection(Val)instead.- Parameters:
selection- TheVarof 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 aValobject and uses it as a basis for modelling theJListselection. If theValobject changes, theJListselection will be updated accordingly. However, if theJListselection changes due to user interaction, theValobject will not be updated.- Parameters:
selection- TheValof entries to set as selection model.- Returns:
- This instance of the builder node to allow for fluent method chaining.
-
withRenderComponent
TheListEntryRendererpassed to this method is a functional interface receiving aListEntryDelegateinstance and returns aJComponent, which is used to render each entry of theJListinstance.
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
JListis 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 aJComponentinstance that is used by theJListto 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- TheListEntryRendererthat will be used to supplyJComponents responsible for rendering each entry of theJListinstance.- 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 anActionevent handler to the underlyingJListthrough aListSelectionListener, which will be called when a list selection has been made. {see JList#addListSelectionListener(ListSelectionListener)}.- Parameters:
action- TheActionthat will be notified.- Returns:
- This very instance, which enables builder-style method chaining.
-
withCellRenderer
Sets theListCellRendererfor 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- TheListCellRendererthat 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 usingObjectas a common type using the fluent builder API exposed to theConfiguratorlambda 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() ) );JComboBoxandJTablecomponents, 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 theJListinstance. TheConfiguratorlambda function passed to this method receives aCellConfexposing 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; }) ) )JListis created for an array of objects. TheConfiguratorlambda 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- TheConfiguratorlambda function that configures the cell view.- Returns:
- This instance of the builder node to allow for fluent method chaining.
-