Java JList Select downListSelectedIndex(JList sourceList)

Here you can find the source of downListSelectedIndex(JList sourceList)

Description

down List Selected Index

License

Open Source License

Declaration

public static void downListSelectedIndex(JList sourceList) 

Method Source Code

//package com.java2s;
import javax.swing.DefaultListModel;
import javax.swing.JList;

public class Main {
    public static void downListSelectedIndex(JList sourceList) {
        int selectedIndex = sourceList.getSelectedIndex();
        DefaultListModel listModel = (DefaultListModel) sourceList
                .getModel();//from   w  w  w.  j av a2 s .co  m
        if (selectedIndex < listModel.size() - 1) {

            Object selectedValue = listModel.get(selectedIndex);
            Object newSelectedValue = listModel.get(selectedIndex + 1);
            listModel.set(selectedIndex, newSelectedValue);
            listModel.set(selectedIndex + 1, selectedValue);
            sourceList.setSelectedIndex(selectedIndex + 1);
            sourceList.ensureIndexIsVisible(sourceList.getSelectedIndex());
        }
    }
}

Related

  1. adaptToList(final JComponent renderer, JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
  2. applyDefaultDisplaySettings(JList list, int index, boolean selected, boolean cellHasFocus, JComponent renderer)
  3. canMoveSelectedItemsUp(JList list)
  4. createStringFromSelectionList( JList aListComponent, boolean createQuotes)
  5. ensureSelectionIsVisible(final JList list)
  6. fillSelectionListFromString(JList aListComponent, String theList, boolean removeQuotes)
  7. fireSelectRow(final JList list, final Object value)
  8. fireSelectRows(final JList list, final int[] rows)