hide JTable Columns - Java Swing

Java examples for Swing:JTable Column

Description

hide JTable Columns

Demo Code


//package com.java2s;

import javax.swing.JTable;

import javax.swing.table.TableColumn;

public class Main {
    /**//from  w w w. j  a v  a  2  s  .  co m
     * @param table
     * @param cols
     * @see {@link #hiddenColumn(JTable, int)}
     */
    public static void hideColumns(JTable table, int[] cols) {
        for (int i = 0; i < cols.length; i++) {
            hiddenColumn(table, cols[i]);
        }
    }

    public static void hiddenColumn(JTable table, int columnIndex) {
        int columnCount = table.getColumnCount();
        if (columnIndex < 0 || columnIndex > columnCount)
            throw new IllegalArgumentException(
                    "TableUtils.hiddenColumn()");
        TableColumn tc = table.getColumnModel().getColumn(columnIndex);
        tc.setMaxWidth(0);
        tc.setMinWidth(0);
        tc.setPreferredWidth(0);
    }
}

Related Tutorials