List of utility methods to do JList Select
List | getSelectedItems(DefaultListModel get Selected Items int iMin = selectionModel.getMinSelectionIndex(); int iMax = selectionModel.getMaxSelectionIndex(); final ArrayList<T> itemList = new ArrayList<>(); if (iMin < 0 || iMax < 0) { return itemList; for (int i = iMin; i <= iMax; i++) { if (selectionModel.isSelectedIndex(i)) { ... |
Object[] | getSelectedMultipleList(JList anJList) fillList Object[] el = null;
el = anJList.getSelectedValues();
return el;
|
int[] | getSelectedRows(ListSelectionModel listSelectionModel) get Selected Rows int iMin = listSelectionModel.getMinSelectionIndex(); int iMax = listSelectionModel.getMaxSelectionIndex(); if ((iMin == -1) || (iMax == -1)) { return new int[0]; int[] rvTmp = new int[1 + (iMax - iMin)]; int n = 0; for (int i = iMin; i <= iMax; i++) { ... |
void | initParamList(final JList paramList, final String[] availNames, final String[] defaultSelection) init Param List final List selectedValues = paramList.getSelectedValuesList(); paramList.removeAll(); paramList.setListData(availNames); paramList.setFixedCellWidth(200); paramList.setMinimumSize(new Dimension(50, 4)); final int size = paramList.getModel().getSize(); final List<Integer> indices = new ArrayList<>(size); for (Object selectedValue : selectedValues) { ... |
void | JListRemoveSelectedObject(javax.swing.JList list) J List Remove Selected Object Object sel = list.getSelectedValue(); if (sel != null) { javax.swing.ListModel lm = list.getModel(); Object[] newList = new Object[lm.getSize() - 1]; int cur = 0; for (int i = 0; i < lm.getSize(); i++) { if (lm.getElementAt(i) != sel) newList[cur++] = lm.getElementAt(i); ... |
void | linkEnabledToSelected(final JComponent component, final ListSelectionModel model) Links the enabled state of the specified component to the selected state of the specified ListSelectionModel .
component.setEnabled(!model.isSelectionEmpty()); model.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) component.setEnabled(!model.isSelectionEmpty()); }); ... |
void | moveSelectedItems(JList list, int nrRows) Move selected Items in the JList DefaultListModel model = (DefaultListModel) list.getModel(); int[] selection = list.getSelectedIndices(); if (selection.length == 0) { return; Object[] items = new Object[selection.length]; for (int i = selection.length - 1; i >= 0; i--) { items[i] = model.remove(selection[i]); ... |
void | moveSourceSelection(JList sourceList, boolean moveDown, boolean byPage) move Source Selection int size = sourceList.getModel().getSize(); if (size > 0) { boolean rollOverEnabled = false; int index = sourceList.getSelectedIndex(); int newIndex = 0; if (index >= 0) { int maxIndex = size - 1; int moveBy = byPage ? sourceList.getVisibleRowCount() : 1; ... |
void | removeListSelectionListeners(final JList comp) Removes the ListSelection Listeners. if (comp != null) { for (ListSelectionListener l : comp.getListSelectionListeners()) { comp.removeListSelectionListener(l); |
void | removeSelectedListItems(JList sourceList) remove Selected List Items int sItemSelectedIndex = sourceList.getSelectedIndex(); Object[] sItemSelectedValues = sourceList.getSelectedValues(); DefaultListModel selectedTableListModel = (DefaultListModel) sourceList.getModel(); if (selectedTableListModel.size() > 0) { for (int i = sItemSelectedValues.length - 1; i >= 0; i--) { selectedTableListModel.removeElement(sItemSelectedValues[i]); if (sItemSelectedIndex >= 0) { if (sItemSelectedIndex >= selectedTableListModel.size()) { sourceList.setSelectedIndex(selectedTableListModel.size() - 1); } else { sourceList.setSelectedIndex(sItemSelectedIndex); |