Java JTable Select copyTableSelectionsToJList(JList list, JTable listTbl)

Here you can find the source of copyTableSelectionsToJList(JList list, JTable listTbl)

Description

Synchronisiert eine JList mit einem JTable.

License

Open Source License

Parameter

Parameter Description
list a parameter
listTbl a parameter

Declaration

public static void copyTableSelectionsToJList(JList list, JTable listTbl) 

Method Source Code

//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);
    }
}

Related

  1. createJCheckBoxForTable(boolean selected)
  2. disableSelection(JTable table)
  3. getSelectedCase(JTable table)
  4. getSelectedObject(JTable table)