Java JList Select moveSourceSelection(JList sourceList, boolean moveDown, boolean byPage)

Here you can find the source of moveSourceSelection(JList sourceList, boolean moveDown, boolean byPage)

Description

move Source Selection

License

Open Source License

Declaration

public static void moveSourceSelection(JList sourceList, boolean moveDown, boolean byPage) 

Method Source Code

//package com.java2s;
/**/*from  w  w w.j  a  va2 s  . c  o  m*/
 * Copyright 2001-2014 CryptoHeaven Corp. All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of CryptoHeaven Corp. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with CryptoHeaven Corp.
 */

import javax.swing.*;

public class Main {
    public static void moveSourceSelection(JList sourceList, boolean moveDown, boolean byPage) {
        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;
                if (moveBy < 1)
                    moveBy = 1;
                if (!moveDown)
                    moveBy = -moveBy;
                newIndex = index + moveBy;
                if (rollOverEnabled) {
                    if (newIndex < 0 && index > 0)
                        newIndex = 0;
                    else if (newIndex > maxIndex && index < maxIndex)
                        newIndex = maxIndex;
                    else if (newIndex < 0)
                        newIndex = maxIndex;
                    else if (newIndex > maxIndex)
                        newIndex = 0;
                } else {
                    if (newIndex < 0)
                        newIndex = 0;
                    else if (newIndex > maxIndex)
                        newIndex = maxIndex;
                }
            }
            sourceList.setSelectedIndex(newIndex);
            sourceList.ensureIndexIsVisible(newIndex);
        }
    }
}

Related

  1. getSelectedRows(ListSelectionModel listSelectionModel)
  2. initParamList(final JList paramList, final String[] availNames, final String[] defaultSelection)
  3. JListRemoveSelectedObject(javax.swing.JList list)
  4. linkEnabledToSelected(final JComponent component, final ListSelectionModel model)
  5. moveSelectedItems(JList list, int nrRows)
  6. removeListSelectionListeners(final JList comp)
  7. removeSelectedListItems(JList sourceList)
  8. removeSelectionFromList(JList fileList)
  9. removeTypeSelectionListener(JList list)