ement 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);
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
@author Jeanette Winzenburg