Removes all JTable columns of the given column model. - Java Swing

Java examples for Swing:JTable Model

Description

Removes all JTable columns of the given column model.

Demo Code


import java.awt.Component;
import java.util.Collections;
import java.util.List;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

public class Main{
    /**//from  ww  w. j  a va 2 s .c  o m
     * Removes all columns of the given column model. Includes hidden
     * columns as indicated by the includesHidden flag, the flag has no 
     * effect if the model is not of type TableColumnModelExt.<p>
     * 
     * @param model the column model to remove all columns from.
     * @param includeHidden indicates whether hidden columns should be 
     *   removed as well, has no effect if model is not of type TableColumnModelExt.
     */
    /*
     * Stand-in instead of fixing of issue http://java.net/jira/browse/SWINGX-1407
     */
    public static void clear(TableColumnModel model, boolean includeHidden) {
        if (model instanceof TableColumnModelExt) {
            clear(model,
                    ((TableColumnModelExt) model).getColumns(includeHidden));
        } else {
            clear(model, Collections.list(model.getColumns()));
        }
    }
    private static void clear(TableColumnModel model,
            List<TableColumn> columns) {
        for (TableColumn tableColumn : columns) {
            model.removeColumn(tableColumn);
        }
    }
}

Related Tutorials