List of utility methods to do JList Select
void | removeSelectionFromList(JList fileList) Removes the selected entry from the given list. if (fileList.getSelectedIndex() > -1) {
((DefaultListModel) fileList.getModel()).remove(fileList.getSelectedIndex());
|
void | removeTypeSelectionListener(JList list) Every list component during construction registers a special handler that lets the user type letters and select elements in the list. KeyListener[] kls = list.getListeners(KeyListener.class); for (KeyListener kl : kls) { String name = kl.getClass().getName(); if (name.endsWith("BasicListUI$Handler")) list.removeKeyListener(kl); |
void | selectByTyping(javax.swing.JList list, javax.swing.JTextField textfield) This method selects the first entry in the JList list that start with the text that is entered in the filter-textfield textfield . String text = textfield.getText().toLowerCase(); ListModel lm = list.getModel(); for (int cnt = 0; cnt < lm.getSize(); cnt++) { String val = lm.getElementAt(cnt).toString(); if (val.toLowerCase().startsWith(text)) { list.setSelectedIndex(cnt); list.ensureIndexIsVisible(cnt); return; ... |
void | selectRow(int row, ListSelectionModel model) select Row if (model == null) { return; model.setSelectionInterval(row, row); |
void | selectStringInList(String string, JList list) Select an item in a JList given an items string value for (int i = 0; i < list.getModel().getSize(); i++) { if (String.valueOf(list.getModel().getElementAt(i)).equals(string)) { list.setSelectedIndex(i); return; |
void | setJListSelection(List selection, JList list) Sets the selected items on a JList , which is a tedious task to do by hand. List modelItems = new ArrayList(); ListModel listModel = list.getModel(); for (int i = 0; i < listModel.getSize(); i++) { modelItems.add(listModel.getElementAt(i)); List indices = new ArrayList(); Iterator items = selection.iterator(); while (items.hasNext()) { ... |
void | setLeadAnchorWithoutSelection(ListSelectionModel model, int lead, int anchor) Set the lead and anchor without affecting selection. if (anchor == -1) { anchor = lead; if (lead == -1) { model.setAnchorSelectionIndex(-1); model.setLeadSelectionIndex(-1); } else { if (model.isSelectedIndex(lead)) { ... |
void | setSelectedItems(JList list, List selected) _more_ List items = getItems(list); int cnt = 0; int[] indices = new int[items.size()]; for (int i = 0; i < selected.size(); i++) { int idx = items.indexOf(selected.get(i)); if (idx < 0) { continue; indices[cnt++] = idx; if (cnt > 0) { int[] realIndices = new int[cnt]; for (int i = 0; i < cnt; i++) { realIndices[i] = indices[i]; list.setSelectedIndices(realIndices); |
void | setSelectedList(JList list, Object selected) set Selected List if (list == null) { return; if (list.getModel().getSize() == 0) { return; if (selected == null) { list.setSelectedIndex(0); ... |
void | setSelectedListIndices(final JList list, final List set Selected List Indices final int[] selIndex = new int[indices.size()]; for (int i = 0; i < indices.size(); ++i) { selIndex[i] = indices.get(i); list.setSelectedIndices(selIndex); |