Java Utililty Methods JList

List of utility methods to do JList

Description

The list of methods to do JList are organized into topic(s).

Method

booleanisIndexFullyVisible(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));
voidJListClearData(javax.swing.JList list)
J List Clear Data
list.setListData(new Object[0]);
intloc2IndexFileList(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;
voidnavigateThroughList(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);
voidpickFirstIfNone(JList list)
pick First If None
if (list.isSelectionEmpty()) {
    list.setSelectedIndex(0);
} else {
booleanpointIsInActualBounds(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);
...
booleanpointIsInActualBounds(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);
...
voidsetErrorBackground(JList comp)
set Error Background
comp.setBackground(ERROR_BACKGROUND);
voidupdatebandList(final JList bandList, final Map paramMap, final String paramName)
updateband List
updateParamList(bandList, paramMap, paramName);
voidupdateList(JList list, LinkedHashMap map)
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);
...