Here you can find the source of copyTableSelectionsToJList(JList list, JTable listTbl)
Parameter | Description |
---|---|
list | a parameter |
listTbl | a parameter |
public static void copyTableSelectionsToJList(JList list, JTable listTbl)
//package com.java2s; //License from project: Open Source License import java.util.Vector; import javax.swing.JList; import javax.swing.JTable; public class Main { /**//from ww w. java 2 s .c o m * Synchronisiert eine JList mit einem JTable. * * Die Selections werden von dem Table auf die List kopiert. * * @param list * @param listTbl */ public static void copyTableSelectionsToJList(JList list, JTable listTbl) { list.setSelectedIndices(new int[0]); int rows = listTbl.getRowCount(); Vector sel = new Vector(); for (int i = 0; i < rows; i++) { if (listTbl.getSelectionModel().isSelectedIndex(i)) { sel.add(new Integer(listTbl.convertRowIndexToModel(i))); } } int tmp[] = new int[sel.size()]; for (int i = 0; i < sel.size(); i++) tmp[i] = ((Integer) sel.get(i)).intValue(); list.setSelectedIndices(tmp); } }