22
23
import javax.swing.JScrollPane;
23
24
import javax.swing.ListModel;
24
25
import javax.swing.RowFilter;
26
import javax.swing.SwingUtilities;
25
27
import javax.swing.UIManager;
28
import javax.swing.event.ListSelectionEvent;
29
import javax.swing.event.ListSelectionListener;
26
30
import javax.swing.plaf.UIResource;
28
32
import org.jdesktop.swingx.decorator.ColorHighlighter;
33
import org.jdesktop.swingx.decorator.ComponentAdapter;
29
34
import org.jdesktop.swingx.decorator.HighlightPredicate;
35
import org.jdesktop.swingx.decorator.Highlighter;
30
36
import org.jdesktop.swingx.decorator.HighlighterFactory;
31
37
import org.jdesktop.swingx.decorator.PatternPredicate;
32
38
import org.jdesktop.swingx.hyperlink.EditorPaneLinkVisitor;
72
* Issue #1261-swingx: list goes blank after setting model and filter.
75
* - click on setModel: resets the model and turns on filter (expected)
76
* - click on filterOff: clears the list (unexpected - the expected behaviour
77
* is to show all entries
80
* - click on invalidate to explicitly invalidated the cell size cache
81
* (should be done automatically) - fixed to now do in ListSortUI.sorterChanged
83
* example adjusted from reporter
85
public void interactiveRowFilterAfterSetModel() {
86
final JXList list = new JXList(true);
87
JXFrame frame = wrapWithScrollingInFrame(list, "filter after model");
89
final Action filterOnAction = new AbstractAction("filter on") {
92
public void actionPerformed(ActionEvent e) {
93
list.setRowFilter(new RowFilter<ListModel, Integer>() {
96
public boolean include(
97
Entry<? extends ListModel, ? extends Integer> entry) {
98
boolean include = entry.getStringValue(entry.getIdentifier())
99
.toLowerCase().contains("o");
107
// addAction(frame, filterOnAction);
109
Action modelAction = new AbstractAction("setModel") {
112
public void actionPerformed(ActionEvent e) {
113
DefaultListModel model = new DefaultListModel();
114
model.addElement("One" + count++);
115
model.addElement("Two");
116
model.addElement("Three");
117
model.addElement("Four");
118
model.addElement("Five");
119
list.setModel(model);
120
filterOnAction.actionPerformed(e);
123
addAction(frame, modelAction);
125
Action filterOffAction = new AbstractAction("filter off") {
128
public void actionPerformed(ActionEvent e) {
129
list.setRowFilter(new RowFilter<ListModel, Integer>() {
132
public boolean include(
133
Entry<? extends ListModel, ? extends Integer> entry) {
141
addAction(frame, filterOffAction);
143
Action invalidateCacheAction = new AbstractAction("invalidateCache") {
146
public void actionPerformed(ActionEvent e) {
147
// this shouldn't be necessary
148
list.invalidateCellSizeCache();
151
addAction(frame, invalidateCacheAction);
152
addStatusMessage(frame, "setModel == new Model + rowFilter on; filterOff = rowFilter off (should show all)");
153
show(frame, 500, 300);
157
* Issue #1255-swingx: enhance dynamic row sizing.
159
public void interactiveDynamicCellHeight() {
160
final JXList list = new JXList(AncientSwingTeam.createNamedColorListModel(), true);
161
ListSelectionListener l = new ListSelectionListener() {
164
public void valueChanged(final ListSelectionEvent e) {
165
SwingUtilities.invokeLater(new Runnable() {
167
list.invalidateCellSizeCache();
173
list.addListSelectionListener(l);
174
HighlightPredicate selected = new HighlightPredicate() {
177
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
178
return adapter.isSelected();
181
Highlighter hl = new FontHighlighter(selected, list.getFont().deriveFont(50f));
182
list.addHighlighter(hl);
183
JXFrame frame = wrapWithScrollingInFrame(list, "big font on focus");
184
Action toggleSort = new AbstractAction("toggle sort") {
187
public void actionPerformed(ActionEvent e) {
188
list.toggleSortOrder();
191
addAction(frame, toggleSort);
65
196
* Issue 1161-swingx: JXList not completely updated on setRowFilter
66
197
* Issue 1162-swingx: JXList getNextMatch access model directly