Hide a JTable column - Java Swing

Java examples for Swing:JTable Column

Description

Hide a JTable column

Demo Code


//package com.java2s;

import javax.swing.JTable;

import javax.swing.table.TableColumn;

public class Main {

    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);//from   w ww  .j  a  v a 2 s.  c o m
        tc.setMinWidth(0);
        tc.setPreferredWidth(0);
    }
}

Related Tutorials