List of utility methods to do JList
boolean | isIndexFullyVisible(JList list, int index) is Index Fully Visible int first = list.getFirstVisibleIndex(); int last = list.getLastVisibleIndex(); if (index < 0 || first < 0 || last < 0 || index < first || index > last) { return false; if (index > first && index < last) { return true; return list.getVisibleRect().contains(list.getCellBounds(index, index)); |
void | JListClearData(javax.swing.JList list) J List Clear Data list.setListData(new Object[0]);
|
int | loc2IndexFileList(JList list, Point point) loc Index File List int index = list.locationToIndex(point); if (index != -1) { Object bySize = list.getClientProperty("List.isFileList"); if (bySize instanceof Boolean && ((Boolean) bySize).booleanValue() && !pointIsInActualBounds(list, index, point)) { index = -1; return index; |
void | navigateThroughList(javax.swing.JList list, int keyCode) navigate Through List if (KeyEvent.VK_LEFT == keyCode || KeyEvent.VK_RIGHT == keyCode) { return; int selectedRow = list.getSelectedIndex(); ListModel lm = list.getModel(); if (-1 == selectedRow) { selectedRow = 0; switch (keyCode) { case KeyEvent.VK_HOME: selectedRow = 0; break; case KeyEvent.VK_END: selectedRow = lm.getSize() - 1; break; case KeyEvent.VK_DOWN: if (lm.getSize() > (selectedRow + 1)) { selectedRow++; break; case KeyEvent.VK_UP: if (selectedRow > 0) { selectedRow--; break; list.setSelectedIndex(selectedRow); list.ensureIndexIsVisible(selectedRow); |
void | pickFirstIfNone(JList list) pick First If None if (list.isSelectionEmpty()) { list.setSelectedIndex(0); } else { |
boolean | pointIsInActualBounds(JList list, int index, Point point) Returns true if the given point is within the actual bounds of the JList item at index (not just inside the cell). ListCellRenderer renderer = list.getCellRenderer();
ListModel dataModel = list.getModel();
Object value = dataModel.getElementAt(index);
Component item = renderer.getListCellRendererComponent(list, value, index, false, false);
Dimension itemSize = item.getPreferredSize();
Rectangle cellBounds = list.getCellBounds(index, index);
if (!item.getComponentOrientation().isLeftToRight()) {
cellBounds.x += (cellBounds.width - itemSize.width);
...
|
boolean | pointIsInActualBounds(JList list, int index, Point point) point Is In Actual Bounds ListCellRenderer renderer = list.getCellRenderer();
ListModel dataModel = list.getModel();
Object value = dataModel.getElementAt(index);
Component item = renderer.getListCellRendererComponent(list, value, index, false, false);
Dimension itemSize = item.getPreferredSize();
Rectangle cellBounds = list.getCellBounds(index, index);
if (!item.getComponentOrientation().isLeftToRight()) {
cellBounds.x += (cellBounds.width - itemSize.width);
...
|
void | setErrorBackground(JList comp) set Error Background comp.setBackground(ERROR_BACKGROUND); |
void | updatebandList(final JList bandList, final Map updateband List updateParamList(bandList, paramMap, paramName); |
void | updateList(JList list, LinkedHashMap update List DefaultListModel listValue = new DefaultListModel(); list.removeAll(); Iterator<Map.Entry<K, V>> iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = iter.next(); listValue.addElement(entry.getKey().toString()); list.setModel(listValue); ... |