Here you can find the source of moveSourceSelection(JList sourceList, boolean moveDown, boolean byPage)
public static void moveSourceSelection(JList sourceList, boolean moveDown, boolean byPage)
//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); } } }