get Column Names from JTable - Java Swing

Java examples for Swing:JTable Column

Description

get Column Names from JTable

Demo Code


//package com.java2s;
import javax.swing.table.TableModel;

public class Main {
    /**// w  w  w  .j a v a 2 s . co  m
     * @param tableModel
     * @return the list of column names of a table
     */
    public static String[] getColumnNames(TableModel tableModel) {
        int size = tableModel.getColumnCount();
        String[] columnNames = new String[size];
        for (int i = 0; i < size; i++) {
            columnNames[i] = tableModel.getColumnName(i);
        }
        return columnNames;
    }
}

Related Tutorials