Returns the JTable column index for a specific column within the table. - Java Swing

Java examples for Swing:JTable Column

Description

Returns the JTable column index for a specific column within the table.

Demo Code


//package com.java2s;

import javax.swing.JTable;

public class Main {
    /**//from   www  .j  a  v a 2  s. c  o  m
     * Returns the column index for a specific column within the table.
     * @param table The JTable.
     * @param columnName The column name.
     * @return the column index for a specific column.
     */
    public static int getColumnIndex(JTable table, String columnName) {
        for (int i = 0; i < table.getColumnCount(); ++i)
            if (table.getColumnName(i).equals(columnName))
                return i;
        return -1;
    }
}

Related Tutorials