Java JList navigateThroughList(javax.swing.JList list, int keyCode)

Here you can find the source of navigateThroughList(javax.swing.JList list, int keyCode)

Description

navigate Through List

License

Open Source License

Declaration

public static void navigateThroughList(javax.swing.JList list, int keyCode) 

Method Source Code


//package com.java2s;
/*/*from w  w w .  ja  v  a  2s.co m*/
 * Zettelkasten - nach Luhmann
 ** Copyright (C) 2001-2014 by Daniel L?decke (http://www.danielluedecke.de)
 * 
 * Homepage: http://zettelkasten.danielluedecke.de
 * 
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 3 of 
 * the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, see <http://www.gnu.org/licenses/>.
 * 
 * 
 * Dieses Programm ist freie Software. Sie k?nnen es unter den Bedingungen der GNU
 * General Public License, wie von der Free Software Foundation ver?ffentlicht, weitergeben
 * und/oder modifizieren, entweder gem?? Version 3 der Lizenz oder (wenn Sie m?chten)
 * jeder sp?teren Version.
 * 
 * Die Ver?ffentlichung dieses Programms erfolgt in der Hoffnung, da? es Ihnen von Nutzen sein 
 * wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die implizite Garantie der MARKTREIFE oder 
 * der VERWENDBARKEIT F?R EINEN BESTIMMTEN ZWECK. Details finden Sie in der 
 * GNU General Public License.
 * 
 * Sie sollten ein Exemplar der GNU General Public License zusammen mit diesem Programm 
 * erhalten haben. Falls nicht, siehe <http://www.gnu.org/licenses/>.
 */

import java.awt.event.KeyEvent;
import javax.swing.ListModel;

public class Main {

    public static void navigateThroughList(javax.swing.JList list, int keyCode) {
        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);
    }
}

Related

  1. indexOf(JList jList, Object obj)
  2. isDoubleClick(MouseEvent evt, JList lst, JButton btn)
  3. isIndexFullyVisible(JList list, int index)
  4. JListClearData(javax.swing.JList list)
  5. loc2IndexFileList(JList list, Point point)
  6. pickFirstIfNone(JList list)
  7. pointIsInActualBounds(JList list, int index, Point point)
  8. pointIsInActualBounds(JList list, int index, Point point)
  9. setErrorBackground(JList comp)