Example usage for javax.swing.table TableColumnModel removeColumn

List of usage examples for javax.swing.table TableColumnModel removeColumn

Introduction

In this page you can find the example usage for javax.swing.table TableColumnModel removeColumn.

Prototype

public void removeColumn(TableColumn column);

Source Link

Document

Deletes the TableColumn column from the tableColumns array.

Usage

From source file:org.pentaho.reporting.ui.datasources.table.TableEditor.java

/**
 * Creates default columns for the table from the data model using the <code>getColumnCount</code> method defined in
 * the <code>TableModel</code> interface.
 * <p/>/*from  w  ww  .jav  a 2 s  . c o m*/
 * Clears any existing columns before creating the new columns based on information from the model.
 *
 * @see #getAutoCreateColumnsFromModel
 */
public void createDefaultColumnsFromModel() {
    final TableModel m = getModel();
    if (m != null) {
        // Remove any current columns
        final TableColumnModel cm = getColumnModel();
        while (cm.getColumnCount() > 0) {
            cm.removeColumn(cm.getColumn(0));
        }

        // Create new columns from the data model info
        for (int i = 0; i < m.getColumnCount(); i++) {
            if (i == 0) {
                final TableColumn column = new TableColumn(i);
                column.setCellRenderer(tableHeader.getDefaultRenderer());
                addColumn(column);
                continue;
            }

            final EditableHeaderTableColumn newColumn = new EditableHeaderTableColumn(i);
            newColumn.setHeaderEditor(new TypedHeaderCellEditor());
            addColumn(newColumn);
        }
    }
}