JXList extends JList { @Override public void setSelectedValue(Object anObject,boolean shouldScroll) { if(anObject == null) setSelectedIndex(-1); else if(!anObject.equals(getSelectedValue())) { int i,c; for(i=0,c=getElementCount();i<c;i++) if(anObject.equals(getElementAt(i))){ setSelectedIndex(i); if(shouldScroll) ensureIndexIsVisible(i); repaint(); return; } setSelectedIndex(-1); } repaint(); } JXList();  JXList(ListModel dataModel);  JXList(Object[] listData);  JXList(Vector<?> listData);  JXList(boolean autoCreateRowSorter);  JXList(ListModel dataModel, boolean autoCreateRowSorter);  JXList(Object[] listData, boolean autoCreateRowSorter);  JXList(Vector<?> listData, boolean autoCreateRowSorter); Searchable getSearchable(); void setSearchable(Searchable searchable); @Override int getNextMatch(String prefix, int startIndex, Bias bias); void setRolloverEnabled(boolean rolloverEnabled); boolean isRolloverEnabled(); @Override Point getPopupLocation(MouseEvent event); Point getPopupTriggerLocation(); boolean getAutoCreateRowSorter(); void setAutoCreateRowSorter(boolean autoCreateRowSorter); RowSorter<? extends ListModel> getRowSorter(); void setRowSorter(RowSorter<? extends ListModel> sorter); void setSortable(boolean sortable); boolean isSortable(); void setSortsOnUpdates(boolean sortsOnUpdates); boolean getSortsOnUpdates(); void setSortOrderCycle(SortOrder... cycle); SortOrder[] getSortOrderCycle(); Comparator<?> getComparator(); void setComparator(Comparator<?> comparator); @SuppressWarnings("unchecked") void setRowFilter(RowFilter<? super R, ? super Integer> filter); @SuppressWarnings("unchecked") RowFilter<?, ?> getRowFilter(); void resetSortOrder(); void toggleSortOrder(); void setSortOrder(SortOrder sortOrder); SortOrder getSortOrder(); Object getElementAt(int viewIndex); @Override Object getSelectedValue(); @Override void setSelectedValue(Object anObject,boolean shouldScroll); @Override Object[] getSelectedValues(); int getElementCount(); int convertIndexToModel(int viewIndex); int convertIndexToView(int modelIndex); @Override void setModel(ListModel model); void setHighlighters(Highlighter... highlighters); Highlighter[] getHighlighters(); void addHighlighter(Highlighter highlighter); void removeHighlighter(Highlighter highlighter); String getStringAt(int row); @Override ListCellRenderer getCellRenderer(); ListCellRenderer getWrappedCellRenderer(); @Override void setCellRenderer(ListCellRenderer renderer); void invalidateCellSizeCache(); @Override void updateUI(); @Override String getUIClassID(); final static String uiClassID; static final String EXECUTE_BUTTON_ACTIONCOMMAND; }
@Test public void testSetSelectedValue() { DefaultListModel model = new DefaultListModel(); model.addElement("One"); model.addElement("Two"); model.addElement("Three"); model.addElement("Four"); model.addElement("Five"); model.addElement("Six"); model.addElement("Seven"); JXList list = new JXList(); list.setAutoCreateRowSorter(true); list.setModel(model); list.setSelectedValue("Three", false); assertEquals(2, list.getSelectedIndex()); list.setRowFilter(new RowFilter<ListModel, Integer>() { @Override public boolean include(Entry<? extends ListModel, ? extends Integer> entry) { return entry.getStringValue(entry.getIdentifier()).contains("e"); } }); assertEquals(1, list.getSelectedIndex()); list.setSelectedValue("Five", false); assertEquals(2, list.getSelectedIndex()); }