Converts the selected view indexes to model indexes. - Java Swing

Java examples for Swing:JTable Model

Description

Converts the selected view indexes to model indexes.

Demo Code

/*/*from   w  w w .j a v a  2  s. c  om*/
 * Copyright 2008-2014, David Karnok 
 * The file is part of the Open Imperium Galactica project.
 * 
 * The code should be distributed under the LGPL license.
 * See http://www.gnu.org/licenses/lgpl.html for details.
 */
//package com.java2s;

import javax.swing.JTable;

public class Main {
    /**
     * Converts the selected view indexes to model indexes.
     * @param table the table
     * @return the selected model indices
     */
    public static int[] convertSelectionToModel(JTable table) {
        int[] selected = table.getSelectedRows();
        for (int i = 0; i < selected.length; i++) {
            selected[i] = table.convertRowIndexToModel(selected[i]);
        }
        return selected;
    }
}

Related Tutorials