Class JXList<E>
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
,Scrollable
Sorting and Filtering
JXList supports sorting and filtering. Changed to use core support. Usage is very similar to J/X/Table. It provides api to apply a specific sort order, to toggle the sort order and to reset a sort. Sort sequence can be configured by setting a custom comparator.
list.setAutoCreateRowSorter(true);
list.setComparator(myComparator);
list.setSortOrder(SortOrder.DESCENDING);
list.toggleSortOder();
list.resetSortOrder();
JXList provides api to access items of the underlying model in view coordinates and to convert from/to model coordinates. Note: JXList needs a specific ui-delegate - BasicXListUI and subclasses - which is aware of model vs. view coordiate systems and which controls the synchronization of selection/dataModel and sorter state. SwingX comes with a subclass for Synth.
Rendering and Highlighting
As all SwingX collection views, a JXList is a HighlighterClient (PENDING JW: formally define and implement, like in AbstractTestHighlighter), that is it provides consistent api to add and remove Highlighters which can visually decorate the rendering component.
JXList list = new JXList(new Contributors());
// implement a custom string representation, concated from first-, lastName
StringValue sv = new StringValue() {
public String getString(Object value) {
if (value instanceof Contributor) {
Contributor contributor = (Contributor) value;
return contributor.lastName() + ", " + contributor.firstName();
}
return StringValues.TO_STRING(value);
}
};
list.setCellRenderer(new DefaultListRenderer(sv);
// highlight condition: gold merits
HighlightPredicate predicate = new HighlightPredicate() {
public boolean isHighlighted(Component renderer,
ComponentAdapter adapter) {
if (!(value instanceof Contributor)) return false;
return ((Contributor) value).hasGold();
}
};
// highlight with foreground color
list.addHighlighter(new PainterHighlighter(predicate, goldStarPainter);
Note: to support the highlighting this implementation wraps the
ListCellRenderer set by client code with a DelegatingRenderer which applies
the Highlighter after delegating the default configuration to the wrappee. As
a side-effect, getCellRenderer does return the wrapper instead of the custom
renderer. To access the latter, client code must call getWrappedCellRenderer.
Rollover
As all SwingX collection views, a JXList supports per-cell rollover. If enabled, the component fires rollover events on enter/exit of a cell which by default is promoted to the renderer if it implements RolloverRenderer, that is simulates live behaviour. The rollover events can be used by client code as well, f.i. to decorate the rollover row using a Highlighter.
JXList list = new JXList();
list.setRolloverEnabled(true);
list.setCellRenderer(new DefaultListRenderer());
list.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW,
null, Color.RED);
Location of Trigger for ComponentPopupMenu
JXList allows access to the mouse location that triggered the showing of the componentPopupMenu. This feature allows to implement dynamic cell-context sensitive popupMenus, either in the menu actions or in a PopupMenuListener.
The example below selects the cell that was clicked, event being the
PopupMenuEvent
received in a
PopupMenuListener
.
JXList list = (JXList) ((JPopupMenu) e.getSource()).getInvoker();
Point trigger = list.getPopupTriggerLocation();
if (trigger != null) {
int row = list.locationToIndex(trigger);
list.setSelectedIndex(row);
}
Search
As all SwingX collection views, a JXList is searchable. A search action is registered in its ActionMap under the key "find". The default behaviour is to ask the SearchFactory to open a search component on this component. The default keybinding is retrieved from the SearchFactory, typically ctrl-f (or cmd-f for Mac). Client code can register custom actions and/or bindings as appropriate.JXList provides api to vend a renderer-controlled String representation of cell content. This allows the Searchable and Highlighters to use WYSIWYM (What-You-See-Is-What-You-Match), that is pattern matching against the actual string as seen by the user.
- Author:
- Ramesh Gupta, Jeanette Winzenburg
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
A decorator for the original ListCellRenderer.protected static class
A component adapter targeted at a JXList.Nested classes/interfaces inherited from class javax.swing.JList
JList.AccessibleJList, JList.DropLocation
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CompoundHighlighter
The pipeline holding the highlighters.protected ComponentAdapter
The ComponentAdapter for model data access.static final String
EXECUTE_BUTTON_ACTIONCOMMANDstatic final String
UI Class IDFields inherited from class javax.swing.JList
HORIZONTAL_WRAP, VERTICAL, VERTICAL_WRAP
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionJXList()
Constructs aJXList
with an empty model and filters disabled.JXList
(boolean autoCreateRowSorter) Constructs aJXList
with an empty model and automatic creation of a RowSorter as given.Constructs aJXList
that displays the elements in the specified array and automatic creation of a RowSorter disabled.Constructs aJXList
that displays the elements in the specified array and automatic creation of a RowSorter as given.Constructs aJXList
that displays the elements in the specifiedVector
and automatic creation of a RowSorter disabled.Constructs aJXList
that displays the elements in the specifiedVector
and filtersEnabled property.Constructs aJXList
that displays the elements in the specified, non-null
model and automatic creation of a RowSorter disabled.Constructs aJXList
with the specified model and automatic creation of a RowSorter as given. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHighlighter
(Highlighter highlighter) Appends aHighlighter
to the end of the list of usedHighlighter
s.protected void
Propagates sort-related properties from table/columns to the sorter if it is of type SortController, does nothing otherwise.int
convertIndexToModel
(int viewIndex) Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters.int
convertIndexToView
(int modelIndex) Convert index from model coordinates to view coordinates accounting for the presence of sorters and filters.protected ListCellRenderer<E>
Creates and returns the default cell renderer to use.Creates and returns the default RowSorter.protected StringValueRegistry
Creates and returns the default registry for StringValues.protected ChangeListener
Creates and returns the ChangeListener observing Highlighters.protected ListRolloverController<JXList<E>>
Creates and returns a RolloverController appropriate for this component.protected RolloverProducer
Creates and returns the RolloverProducer to use with this list.protected void
doFind()
Starts a search on this List's visible items.boolean
Returnstrue
if whenever the model changes, a newRowSorter
should be created and installed as the list's sorter; otherwise, returnsfalse
.Comparator<?>
protected ComponentAdapter
protected ComponentAdapter
getComponentAdapter
(int index) Convenience to access a configured ComponentAdapter.protected CompoundHighlighter
Returns the CompoundHighlighter assigned to the list, null if none.protected boolean
Returns a boolean indicating whether the list configures the sorter's properties.getElementAt
(int viewIndex) Returns the element at the given index.int
Returns the number of elements in this list in view coordinates.protected ChangeListener
Returns theChangeListener
to use with highlighters.Returns theHighlighter
s used by this list.int
getNextMatch
(String prefix, int startIndex, Position.Bias bias) getPopupLocation
(MouseEvent event) Returns the location of the mouseEvent that triggered the showing of the ComponentPopupMenu.protected ListRolloverController<JXList<E>>
Returns the RolloverController for this component.RowFilter<?,
?> Returns the filter of the sorter, if available and of type SortController.Returns the object responsible for sorting.Returns a Searchable for this component, guaranteed to be not null.Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list.Object[]
Deprecated.protected SortController<? extends ListModel<Object>>
Returns the currently active SortController.Returns the SortOrder.Returns the sortOrder cycle used when toggle sorting this list's columns, guaranteed to be not null.boolean
Returns true if a sort should happen when the underlying model is updated; otherwise, returns false.getStringAt
(int row) Returns the string representation of the cell value at the given position.protected StringValueRegistry
Returns the StringValueRegistry which defines the string representation for each cells.ListCellRenderer<? super E>
Returns the renderer installed by client code or the default if none has been set.protected boolean
Returns a boolean indicating whether the list has a SortController.void
Invalidates cell size caching in the ui delegate.boolean
Returns a boolean indicating whether or not rollover support is enabled.boolean
Returns the list's sortable property.void
removeHighlighter
(Highlighter highlighter) Removes the given Highlighter.void
Resets sorting of all columns.void
setAutoCreateRowSorter
(boolean autoCreateRowSorter) Specifies whether aRowSorter
should be created for the list whenever its model changes.void
setCellRenderer
(ListCellRenderer<? super E> renderer) void
setComparator
(Comparator<?> comparator) Sets the comparator to use for sorting.void
setHighlighters
(Highlighter... highlighters) Sets theHighlighter
s to the list, replacing any old settings.void
void
setRolloverEnabled
(boolean rolloverEnabled) Sets the property to enable/disable rollover support.setRowFilter
(RowFilter<? super R, ? super Integer> filter) Sets the filter to the sorter, if available and of type SortController.void
setRowSorter
(RowSorter<? extends ListModel<E>> sorter) Sets theRowSorter
.void
setSearchable
(Searchable searchable) Sets the Searchable for this component.void
setSelectedValue
(Object anObject, boolean shouldScroll) Selects the specified object from the list, taking into account sorting and filtering.void
setSortable
(boolean sortable) Sets "sortable" property indicating whether or not this list isSortable.void
setSortOrder
(SortOrder sortOrder) Sorts the list using SortOrder.void
setSortOrderCycle
(SortOrder... cycle) Sets the sortorder cycle used when toggle sorting this list's columns.void
setSortsOnUpdates
(boolean sortsOnUpdates) If true, specifies that a sort should happen when the underlying model is updated (rowsUpdated
is invoked).void
Toggles the sort order of the list.protected void
Updates highlighter afterupdateUI
changes.protected void
updatePopupTrigger
(MouseEvent event) Handles internal bookkeeping related to popupLocation, called from getPopupLocation.protected void
Updates the SortController's comparator, if available.void
updateUI()
Methods inherited from class javax.swing.JList
addListSelectionListener, addSelectionInterval, clearSelection, createSelectionModel, ensureIndexIsVisible, fireSelectionValueChanged, getAccessibleContext, getAnchorSelectionIndex, getCellBounds, getDragEnabled, getDropLocation, getDropMode, getFirstVisibleIndex, getFixedCellHeight, getFixedCellWidth, getLastVisibleIndex, getLayoutOrientation, getLeadSelectionIndex, getListSelectionListeners, getMaxSelectionIndex, getMinSelectionIndex, getModel, getPreferredScrollableViewportSize, getPrototypeCellValue, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedIndex, getSelectedIndices, getSelectionBackground, getSelectionForeground, getSelectionMode, getSelectionModel, getToolTipText, getUI, getValueIsAdjusting, getVisibleRowCount, indexToLocation, isSelectedIndex, isSelectionEmpty, locationToIndex, paramString, removeListSelectionListener, removeSelectionInterval, setDragEnabled, setDropMode, setFixedCellHeight, setFixedCellWidth, setLayoutOrientation, setListData, setListData, setPrototypeCellValue, setSelectedIndex, setSelectedIndices, setSelectionBackground, setSelectionForeground, setSelectionInterval, setSelectionMode, setSelectionModel, setUI, setValueIsAdjusting, setVisibleRowCount
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
uiClassID
UI Class ID- See Also:
-
getUIClassID()
JComponent.readObject(java.io.ObjectInputStream)
- Constant Field Values
-
EXECUTE_BUTTON_ACTIONCOMMAND
EXECUTE_BUTTON_ACTIONCOMMAND- See Also:
-
compoundHighlighter
The pipeline holding the highlighters. -
dataAdapter
The ComponentAdapter for model data access.
-
-
Constructor Details
-
JXList
public JXList()Constructs aJXList
with an empty model and filters disabled. -
JXList
Constructs aJXList
that displays the elements in the specified, non-null
model and automatic creation of a RowSorter disabled.- Parameters:
dataModel
- the data model for this list- Throws:
IllegalArgumentException
- ifdataModel
isnull
-
JXList
Constructs aJXList
that displays the elements in the specified array and automatic creation of a RowSorter disabled.- Parameters:
listData
- the array of Objects to be loaded into the data model- Throws:
IllegalArgumentException
- iflistData
isnull
-
JXList
Constructs aJXList
that displays the elements in the specifiedVector
and automatic creation of a RowSorter disabled.- Parameters:
listData
- theVector
to be loaded into the data model- Throws:
IllegalArgumentException
- iflistData
isnull
-
JXList
public JXList(boolean autoCreateRowSorter) Constructs aJXList
with an empty model and automatic creation of a RowSorter as given.- Parameters:
autoCreateRowSorter
-boolean
to determine if a RowSorter should be created automatically.
-
JXList
Constructs aJXList
with the specified model and automatic creation of a RowSorter as given.- Parameters:
dataModel
- the data model for this listautoCreateRowSorter
-boolean
to determine if a RowSorter should be created automatically.- Throws:
IllegalArgumentException
- ifdataModel
isnull
-
JXList
Constructs aJXList
that displays the elements in the specified array and automatic creation of a RowSorter as given.- Parameters:
listData
- the array of Objects to be loaded into the data modelautoCreateRowSorter
-boolean
to determine if a RowSorter should be created automatically.- Throws:
IllegalArgumentException
- iflistData
isnull
-
JXList
Constructs aJXList
that displays the elements in the specifiedVector
and filtersEnabled property.- Parameters:
listData
- theVector
to be loaded into the data modelautoCreateRowSorter
-boolean
to determine if a RowSorter should be created automatically.- Throws:
IllegalArgumentException
- iflistData
isnull
-
-
Method Details
-
doFind
protected void doFind()Starts a search on this List's visible items. This implementation asks the SearchFactory to open a find widget on itself. -
getSearchable
Returns a Searchable for this component, guaranteed to be not null. This implementation lazily creates a ListSearchable if necessary.- Returns:
- a not-null Searchable for this list.
- See Also:
-
setSearchable
Sets the Searchable for this component. If null, a default Searchable will be created and used.- Parameters:
searchable
- the Searchable to use for this component, may be null to indicate using the list's default searchable.- See Also:
-
getNextMatch
Overridden to cope with sorting/filtering, taking over completely.
- Overrides:
getNextMatch
in classJList<E>
-
setRolloverEnabled
public void setRolloverEnabled(boolean rolloverEnabled) Sets the property to enable/disable rollover support. If enabled, the list fires property changes on per-cell mouse rollover state, i.e. when the mouse enters/leaves a list cell.This can be enabled to show "live" rollover behaviour, f.i. the cursor over a cell rendered by a JXHyperlink.
Default value is disabled.
- Parameters:
rolloverEnabled
- a boolean indicating whether or not the rollover functionality should be enabled.- See Also:
-
isRolloverEnabled
public boolean isRolloverEnabled()Returns a boolean indicating whether or not rollover support is enabled.- Returns:
- a boolean indicating whether or not rollover support is enabled.
- See Also:
-
getRolloverController
Returns the RolloverController for this component. Lazyly creates the controller if necessary, that is the return value is guaranteed to be not null.- Returns:
- the RolloverController for this list, guaranteed to be not null.
- See Also:
-
createRolloverController
Creates and returns a RolloverController appropriate for this component.- Returns:
- a RolloverController appropriate for this component.
- See Also:
-
createRolloverProducer
Creates and returns the RolloverProducer to use with this list.- Returns:
RolloverProducer
to use with this list- See Also:
-
getPopupLocation
Overridden for bookkeeping: the given event location is stored for later access.
- Overrides:
getPopupLocation
in classJComponent
- See Also:
-
updatePopupTrigger
Handles internal bookkeeping related to popupLocation, called from getPopupLocation.This implementation stores the mouse location as popupTriggerLocation.
- Parameters:
event
- the event that triggered the showing of the componentPopup, might be null if triggered by keyboard
-
getPopupTriggerLocation
Returns the location of the mouseEvent that triggered the showing of the ComponentPopupMenu.- Returns:
- the location of the mouseEvent that triggered the last showing of the ComponentPopup, or null if it was triggered by keyboard.
-
getAutoCreateRowSorter
public boolean getAutoCreateRowSorter()Returnstrue
if whenever the model changes, a newRowSorter
should be created and installed as the list's sorter; otherwise, returnsfalse
.- Returns:
- true if a
RowSorter
should be created when the model changes - Since:
- 1.6
-
setAutoCreateRowSorter
public void setAutoCreateRowSorter(boolean autoCreateRowSorter) Specifies whether aRowSorter
should be created for the list whenever its model changes.When
setAutoCreateRowSorter(true)
is invoked, aRowSorter
is immediately created and installed on the list. While theautoCreateRowSorter
property remainstrue
, every time the model is changed, a newRowSorter
is created and set as the list's row sorter.The default value is false.
- Parameters:
autoCreateRowSorter
- whether or not aRowSorter
should be automatically created
-
createDefaultRowSorter
Creates and returns the default RowSorter. Note that this is already configured to the current ListModel. PENDING JW: review method signature - better expose the need for the model by adding a parameter?- Returns:
- the default RowSorter.
-
getRowSorter
Returns the object responsible for sorting.- Returns:
- the object responsible for sorting
- Since:
- 1.6
-
setRowSorter
Sets theRowSorter
.RowSorter
is used to provide sorting and filtering to aJXList
.This method clears the selection and resets any variable row heights.
If the underlying model of the
RowSorter
differs from that of thisJXList
undefined behavior will result.- Parameters:
sorter
- theRowSorter
;null
turns sorting off
-
configureSorterProperties
protected void configureSorterProperties()Propagates sort-related properties from table/columns to the sorter if it is of type SortController, does nothing otherwise. -
setSortable
public void setSortable(boolean sortable) Sets "sortable" property indicating whether or not this list isSortable. Note: as of post-1.0 this property is propagated to the SortController. Whether or not a change triggers a re-sort is up to either the concrete controller implementation (the default doesn't) or client code. This behaviour is different from old SwingX style sorting.- Parameters:
sortable
- boolean indicating whether or not this component supports sortable columns- See Also:
-
isSortable
public boolean isSortable()Returns the list's sortable property.- Returns:
- true if the list is sortable.
-
setSortsOnUpdates
public void setSortsOnUpdates(boolean sortsOnUpdates) If true, specifies that a sort should happen when the underlying model is updated (rowsUpdated
is invoked). For example, if this is true and the user edits an entry the location of that item in the view may change. The default is true.- Parameters:
sortsOnUpdates
- whether or not to sort on update events
-
getSortsOnUpdates
public boolean getSortsOnUpdates()Returns true if a sort should happen when the underlying model is updated; otherwise, returns false.- Returns:
- whether or not to sort when the model is updated
-
setSortOrderCycle
Sets the sortorder cycle used when toggle sorting this list's columns. This property is propagated to the SortController if controlsSorterProperties is true.- Parameters:
cycle
- the sequence of zero or more not-null SortOrders to cycle through.- Throws:
NullPointerException
- if the array or any of its elements are null
-
getSortOrderCycle
Returns the sortOrder cycle used when toggle sorting this list's columns, guaranteed to be not null.- Returns:
- the sort order cycle used in toggle sort, not null
-
getComparator
- Returns:
- the comparator used.
- See Also:
-
setComparator
Sets the comparator to use for sorting.Note: as of post-1.0 the property is propagated to the SortController, if available. Whether or not a change triggers a re-sort is up to either the concrete controller implementation (the default doesn't) or client code. This behaviour is different from old SwingX style sorting.
- Parameters:
comparator
- the comparator to use.
-
updateSortAfterComparatorChange
protected void updateSortAfterComparatorChange()Updates the SortController's comparator, if available. Does nothing otherwise. -
setRowFilter
Sets the filter to the sorter, if available and of type SortController. Does nothing otherwise.- Type Parameters:
R
- RowFilter, a type which extends ListModel- Parameters:
filter
- the filter used to determine what entries should be included
-
getRowFilter
Returns the filter of the sorter, if available and of type SortController. Returns null otherwise.PENDING JW: generics? had to remove return type from getSortController to make this compilable, so probably wrong.
- Returns:
- the filter used in the sorter.
-
resetSortOrder
public void resetSortOrder()Resets sorting of all columns. Delegates to the SortController if available, or does nothing if not.PENDING JW: method name - consistent in SortController and here.
-
toggleSortOrder
public void toggleSortOrder()Toggles the sort order of the list. Delegates to the SortController if available, or does nothing if not.The exact behaviour is defined by the SortController's toggleSortOrder implementation. Typically a unsorted list is sorted in ascending order, a sorted list's order is reversed.
-
setSortOrder
Sorts the list using SortOrder. Delegates to the SortController if available, or does nothing if not.- Parameters:
sortOrder
- the sort order to use.
-
getSortOrder
Returns the SortOrder. Delegates to the SortController if available, or returns SortOrder.UNSORTED if not.- Returns:
- the current SortOrder
-
getSortController
Returns the currently active SortController. May be null if RowSorter is null or not of type SortController.PENDING JW: swaying about hiding or not - currently the only way to make the view not configure a RowSorter of type SortController is to let this return null.
- Returns:
- the currently active
SortController
may be null
-
hasSortController
protected boolean hasSortController()Returns a boolean indicating whether the list has a SortController. If true, the call to getSortController is guaranteed to return a not-null value.- Returns:
- a boolean indicating whether the list has a SortController.
- See Also:
-
getControlsSorterProperties
protected boolean getControlsSorterProperties()Returns a boolean indicating whether the list configures the sorter's properties. If true, guaranteed that list's and the columns' sort related properties are propagated to the sorter. If false, guaranteed to not touch the sorter's configuration.This implementation returns true if the sorter is of type SortController. Note: the synchronization is unidirection from the list to the sorter. Changing the sorter under the list's feet might lead to undefined behaviour.
- Returns:
- a boolean indicating whether the list configurers the sorter's properties.
-
getElementAt
Returns the element at the given index. The index is in view coordinates which might differ from model coordinates if filtering is enabled and filters/sorters are active.- Parameters:
viewIndex
- the index in view coordinates- Returns:
- the element at the index
- Throws:
IndexOutOfBoundsException
- if viewIndex < 0 or viewIndex ≥ getElementCount()
-
getSelectedValue
Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list. When multiple items are selected, it is simply the value for the smallest selected index. Returnsnull
if there is no selection.This is a convenience method that simply returns the model value for
getMinSelectionIndex
, taking into account sorting and filtering.- Overrides:
getSelectedValue
in classJList<E>
- Returns:
- the first selected value
- See Also:
-
setSelectedValue
Selects the specified object from the list, taking into account sorting and filtering.- Overrides:
setSelectedValue
in classJList<E>
- Parameters:
anObject
- the object to selectshouldScroll
-true
if the list should scroll to display the selected object, if one exists; otherwisefalse
-
getSelectedValues
Deprecated.- Overrides:
getSelectedValues
in classJList<E>
-
getSelectedValuesList
use
SortController
as model- Overrides:
getSelectedValuesList
in classJList<E>
-
getElementCount
public int getElementCount()Returns the number of elements in this list in view coordinates. If filters are active this number might be less than the number of elements in the underlying model.- Returns:
- number of elements in this list in view coordinates
-
convertIndexToModel
public int convertIndexToModel(int viewIndex) Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters.- Parameters:
viewIndex
- index in view coordinates- Returns:
- index in model coordinates
- Throws:
IndexOutOfBoundsException
- if viewIndex < 0 or viewIndex ≥ getElementCount()
-
convertIndexToView
public int convertIndexToView(int modelIndex) Convert index from model coordinates to view coordinates accounting for the presence of sorters and filters.- Parameters:
modelIndex
- index in model coordinates- Returns:
- index in view coordinates if the model index maps to a view coordinate or -1 if not contained in the view.
-
setModel
Sets the underlying data model. Note that if isFilterEnabled you must call getWrappedModel to access the model given here. In this case getModel returns a wrapper around the data!
-
getComponentAdapter
- Returns:
- the unconfigured ComponentAdapter.
-
getComponentAdapter
Convenience to access a configured ComponentAdapter. Note: the column index of the configured adapter is always 0.- Parameters:
index
- the row index in view coordinates, must be valid.- Returns:
- the configured ComponentAdapter.
-
setHighlighters
Sets theHighlighter
s to the list, replacing any old settings. None of the given Highlighters must be null.This is a bound property.
Note: as of version #1.257 the null constraint is enforced strictly. To remove all highlighters use this method without param.
- Parameters:
highlighters
- zero or more not null highlighters to use for renderer decoration.- Throws:
NullPointerException
- if array is null or array contains null values.- See Also:
-
getHighlighters
Returns theHighlighter
s used by this list. Maybe empty, but guarantees to be never null.- Returns:
- the Highlighters used by this list, guaranteed to never null.
- See Also:
-
addHighlighter
Appends aHighlighter
to the end of the list of usedHighlighter
s. The argument must not be null.- Parameters:
highlighter
- theHighlighter
to add, must not be null.- Throws:
NullPointerException
- ifHighlighter
is null.- See Also:
-
removeHighlighter
Removes the given Highlighter.Does nothing if the Highlighter is not contained.
- Parameters:
highlighter
- the Highlighter to remove.- See Also:
-
getCompoundHighlighter
Returns the CompoundHighlighter assigned to the list, null if none. PENDING: open up for subclasses again?.- Returns:
- the CompoundHighlighter assigned to the list.
-
getHighlighterChangeListener
Returns theChangeListener
to use with highlighters. Lazily creates the listener.- Returns:
- the ChangeListener for observing changes of highlighters,
guaranteed to be
not-null
-
createHighlighterChangeListener
Creates and returns the ChangeListener observing Highlighters.Here: repaints the list on receiving a stateChanged.
- Returns:
- the ChangeListener defining the reaction to changes of highlighters.
-
getStringValueRegistry
Returns the StringValueRegistry which defines the string representation for each cells. This is strictly for internal use by the list, which has the responsibility to keep in synch with registered renderers.Currently exposed for testing reasons, client code is recommended to not use nor override.
- Returns:
- the current string value registry
-
createDefaultStringValueRegistry
Creates and returns the default registry for StringValues.- Returns:
- the default registry for StringValues.
-
getStringAt
Returns the string representation of the cell value at the given position.- Parameters:
row
- the row index of the cell in view coordinates- Returns:
- the string representation of the cell value as it will appear in the list.
-
createDefaultCellRenderer
Creates and returns the default cell renderer to use. Subclasses may override to use a different type. Here: returns aDefaultListRenderer
.- Returns:
- the default cell renderer to use with this list.
-
getCellRenderer
Overridden to return the delegating renderer which is wrapped around the original to support highlighting. The returned renderer is of type DelegatingRenderer and guaranteed to not-null
- Overrides:
getCellRenderer
in classJList<E>
- See Also:
-
getWrappedCellRenderer
Returns the renderer installed by client code or the default if none has been set.- Returns:
- the wrapped renderer.
- See Also:
-
setCellRenderer
Overridden to wrap the given renderer in a DelegatingRenderer to support highlighting.
Note: the wrapping implies that the renderer returned from the getCellRenderer is not the renderer as given here, but the wrapper. To access the original, use
getWrappedCellRenderer
.- Overrides:
setCellRenderer
in classJList<E>
- See Also:
-
invalidateCellSizeCache
public void invalidateCellSizeCache()Invalidates cell size caching in the ui delegate. May do nothing if there's no safe (i.e. without reflection) way to message the delegate.This implementation calls the corresponding method on BasicXListUI if available, does nothing otherwise.
-
updateUI
public void updateUI()Overridden to update renderer and Highlighters.
-
getUIClassID
- Overrides:
getUIClassID
in classJList<E>
- Returns:
- the custom uiClassID
-
updateHighlighterUI
protected void updateHighlighterUI()Updates highlighter afterupdateUI
changes.- See Also:
-