Class SJList<E>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.grid.Grid<Integer>
com.vaadin.swingbridge.surrogates.SJList<E>
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.grid.Grid<Integer>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.grid.Grid<Integer>>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.grid.Grid<Integer>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.data.event.SortEvent.SortNotifier<com.vaadin.flow.component.grid.Grid<Integer>, com.vaadin.flow.component.grid.GridSortOrder<Integer>>, com.vaadin.flow.data.provider.HasDataGenerators<Integer>, com.vaadin.flow.data.provider.HasDataView<Integer, Void, com.vaadin.flow.component.grid.dataview.GridDataView<Integer>>, com.vaadin.flow.data.provider.HasLazyDataView<Integer, Void, com.vaadin.flow.component.grid.dataview.GridLazyDataView<Integer>>, com.vaadin.flow.data.provider.HasListDataView<Integer, com.vaadin.flow.component.grid.dataview.GridListDataView<Integer>>, ComponentMixin, ContainerMixin, JComponentMixin, Serializable, EventListener, ListDataListener, ListSelectionListener

public class SJList<E> extends com.vaadin.flow.component.grid.Grid<Integer> implements JComponentMixin, ListSelectionListener, ListDataListener
Surrogate for JList (SD_sjlist). Extends Vaadin Grid<Integer> — exactly SJTable's row-index identity, narrowed to a single headerless column. Row indices are the Grid's items, the installed ListModel is the single source of truth (R_swing_is_truth), and the ListSelectionModel (also index-based) bridges directly onto Vaadin Grid's Integer-keyed selection.

Why Grid, not VirtualList / ListBox

Grid is the only Vaadin list-shaped component whose native selection covers all three JDK modes through one call (Grid.setSelectionMode(Grid.SelectionMode) — NONE/SINGLE/MULTI); VirtualList carries no selection at all, and ListBox/MultiSelectListBox are two separate classes (one per mode) a surrogate can't swap between at runtime. Picking Grid also reuses SJTable's proven ListSelectionModel↔Grid selection bridge verbatim and rides the existing SJScrollPane auto-scroll guard (which already detects Grid content) for the universal new JScrollPane(jlist) idiom. The cost — a checkbox column in multi-select mode — is accepted per R_best_effort_behaviour/R_layouts_close_enough (see SD_sjlist). Duplicate .equals() elements (which JList permits) are why the items stay Integer indices, not E: Vaadin Grid keys items by identity and would collide on equal values.

Vaadin-first rendering (R_vaadin_first)

Surrogate-layer code installs a Vaadin Renderer<Integer> via setRenderer(Renderer); the per-cell renderer reads through to model.getElementAt(index) live. The JDK ListCellRenderer surface (return type java.awt.Component clashes with our hierarchy per D_event_port_policy) lives only on the emulator layer (:emulators.JList), which bridges it into a Vaadin ComponentRenderer at the boundary (D_jcombobox). Pure-surrogate users without setRenderer(Renderer) get a default value.toString() Span renderer — fresh-per-call to dodge Vaadin's DOM-adoption diff (D_jcombobox's lesson).

Double-click bridge (locationToIndex)

addMouseListener(SMouseListener) overrides the inherited mixin wire (Grid dispatches item clicks, not component clicks, and the item-click carries the row index). It subscribes addItemClickListener and fires SMouseEvent.MOUSE_CLICKED carrying the browser's click count — so a double-click arrives as clickCount == 2, the canonical "double-click to open" idiom. The clicked index is stashed in ListStateStore.clickIndexStash around the fan-out so locationToIndex(Point) resolves correctly during the user's mouseClicked handler (R_layouts_close_enough — no server-side pixel→index map otherwise). Native Vaadin ItemClickListeners a stage-3 user adds coexist untouched.

R_vaadin_first drop-and-WARN surface

layoutOrientation wrap modes (no Vaadin newspaper-flow list), prototypeCellValue (sizing optimisation), dragEnabled (cross-cutting DnD). visibleRowCount / fixedCellWidth / fixedCellHeight / cell bounds / indexToLocation are round-trip-only or null per R_layouts_close_enough (Vaadin Grid virtualises and owns its own sizing).
See Also:
  • Field Details

  • Constructor Details

    • SJList

      public SJList()
    • SJList

      public SJList(ListModel<E> dataModel)
    • SJList

      public SJList(E[] listData)
    • SJList

      public SJList(Vector<E> listData)
  • Method Details

    • createDefaultSelectionModel

      protected ListSelectionModel createDefaultSelectionModel()
    • getModel

      public ListModel<E> getModel()
    • setModel

      public void setModel(ListModel<E> model)
    • setListData

      public void setListData(E[] listData)
    • setListData

      public void setListData(Vector<E> listData)
    • setRenderer

      public void setRenderer(com.vaadin.flow.data.renderer.Renderer<Integer> renderer)
      Install a Vaadin Renderer<Integer> for the list cells. Replaces the single column. Migrated code at the surrogate stage uses this rather than the JDK ListCellRenderer surface (which lives only on the emulator layer per D_event_port_policy + R_vaadin_first).
    • setSelectionAdjustedByOwner

      public void setSelectionAdjustedByOwner(boolean selectionAdjustedByOwner)
      Whether the code that owns this list's models shifts the selection across the model's inserts and removals itself, so this list only refreshes. false by default: a list listening to its own model shifts its selection itself. An owner that does it on the thread the model fired on, as a JDK JList's UI does, sets it.
    • intervalAdded

      public void intervalAdded(ListDataEvent e)
      Specified by:
      intervalAdded in interface ListDataListener
    • intervalRemoved

      public void intervalRemoved(ListDataEvent e)
      Specified by:
      intervalRemoved in interface ListDataListener
    • contentsChanged

      public void contentsChanged(ListDataEvent e)
      Specified by:
      contentsChanged in interface ListDataListener
    • getListSelectionModel

      public ListSelectionModel getListSelectionModel()
      JDK getSelectionModel(): ListSelectionModel can't coexist with Vaadin Grid's same-named getSelectionModel(): GridSelectionModel<T> (unrelated return types). Per R_vaadin_first the Vaadin shape wins at the surrogate; the emulator (:emulators.JList) keeps the JDK-shaped getter and reaches the model through this differently-named accessor. Same resolution SJTable uses.
    • getJdkSelectionMode

      public int getJdkSelectionMode()
      Current JDK selection mode; used by the emulator for PCE old-value delivery. Reconstructed from the selection model (the source of truth) rather than a redundant shadow field — R_vaadin_first.
    • setSelectionModel

      public void setSelectionModel(ListSelectionModel selectionModel)
    • setSelectionMode

      public void setSelectionMode(int selectionMode)
      JDK selection-mode setter. Validates per JDK contract, updates the underlying ListSelectionModel, and maps to Vaadin Grid's Grid.SelectionMode: SINGLE → SINGLE; the two interval modes both map to MULTI (Vaadin Grid has no single-interval analog — the ListSelectionModel still enforces the JDK contract).
    • valueChanged

      public void valueChanged(ListSelectionEvent e)
      Specified by:
      valueChanged in interface ListSelectionListener
    • setSelectedIndex

      public void setSelectedIndex(int index)
    • setSelectedIndices

      public void setSelectedIndices(int[] indices)
    • getSelectedIndex

      public int getSelectedIndex()
    • getSelectedIndices

      public int[] getSelectedIndices()
    • getMinSelectionIndex

      public int getMinSelectionIndex()
    • getMaxSelectionIndex

      public int getMaxSelectionIndex()
    • isSelectedIndex

      public boolean isSelectedIndex(int index)
    • isSelectionEmpty

      public boolean isSelectionEmpty()
    • getAnchorSelectionIndex

      public int getAnchorSelectionIndex()
    • getLeadSelectionIndex

      public int getLeadSelectionIndex()
    • getSelectedValue

      public E getSelectedValue()
    • getSelectedValuesList

      public List<E> getSelectedValuesList()
    • setSelectedValue

      public void setSelectedValue(Object anObject, boolean shouldScroll)
      Select the cell whose model element equals anObject. null clears the selection. shouldScroll drives ensureIndexIsVisible(int).
    • setSelectionInterval

      public void setSelectionInterval(int anchor, int lead)
    • addSelectionInterval

      public void addSelectionInterval(int anchor, int lead)
    • removeSelectionInterval

      public void removeSelectionInterval(int index0, int index1)
    • clearSelection

      public void clearSelection()
    • getValueIsAdjusting

      public boolean getValueIsAdjusting()
    • setValueIsAdjusting

      public void setValueIsAdjusting(boolean b)
    • ensureIndexIsVisible

      public void ensureIndexIsVisible(int index)
      Scrolls so the row at index is visible.
    • addMouseListener

      public void addMouseListener(SMouseListener l)
      Overrides the inherited ComponentMixin wire — Grid dispatches item clicks (carrying the row index), not generic component clicks. Each SMouseListener gets two Grid subscriptions, combined into one Registration: addItemClickListener fires SMouseEvent.MOUSE_CLICKED carrying the browser click count (single = 1), and addItemDoubleClickListener fires it with clickCount == 2 — the canonical double-click-to-open signal. ItemDoubleClickEvent extends ItemClickEvent, so one translation path serves both. The clicked index is stashed around the fan-out for locationToIndex(Point).

      A real browser double-click also fires the intervening single click (cc=1), which is AWT's escalation rather than an approximation of it: both deliver a full cc=1 dispatch then a full cc=2 one (measured on both sides, D_mouse_listener_bridge).

      Specified by:
      addMouseListener in interface ComponentMixin
    • locationToIndex

      public int locationToIndex(Point location)
      Returns the row index currently being click-dispatched (stashed by addMouseListener(SMouseListener)'s item-click wire), or -1 outside a click dispatch. There is no server-side pixel→index map (R_layouts_close_enough), so the stash is the only honest answer; called from a user mouseClicked handler — the dominant JList idiom — it returns the clicked row.
    • indexToLocation

      public Point indexToLocation(int index)
      R_layouts_close_enough — no server-side cell coordinates.
    • getCellBounds

      public Rectangle getCellBounds(int index0, int index1)
      R_layouts_close_enough — no server-side cell bounds.
    • getLayoutOrientation

      public int getLayoutOrientation()
    • setLayoutOrientation

      public void setLayoutOrientation(int layoutOrientation)
    • getVisibleRowCount

      public int getVisibleRowCount()
    • setVisibleRowCount

      public void setVisibleRowCount(int visibleRowCount)
    • getFixedCellWidth

      public int getFixedCellWidth()
    • setFixedCellWidth

      public void setFixedCellWidth(int width)
    • getFixedCellHeight

      public int getFixedCellHeight()
    • setFixedCellHeight

      public void setFixedCellHeight(int height)
    • getPrototypeCellValue

      public E getPrototypeCellValue()
    • setPrototypeCellValue

      public void setPrototypeCellValue(E prototypeCellValue)
    • getSelectionForeground

      public Color getSelectionForeground()
    • setSelectionForeground

      public void setSelectionForeground(Color selectionForeground)
    • getSelectionBackground

      public Color getSelectionBackground()
    • setSelectionBackground

      public void setSelectionBackground(Color selectionBackground)
    • getDragEnabled

      public boolean getDragEnabled()
    • setDragEnabled

      public void setDragEnabled(boolean dragEnabled)
    • getUIClassID

      public String getUIClassID()
      Description copied from interface: JComponentMixin
      Deliberate no-op — L&F key.
      Specified by:
      getUIClassID in interface JComponentMixin