ui/src/main/java/ucar/nc2/ui/table/HidableTableColumnModel.java
public void createColumnsFromModel(TableModel newModel) {
        if (newModel != model) {
            if (model != null) {
                model.removeTableModelListener(this);  // Stop listening to old model.
            }

            newModel.addTableModelListener(this);  // Start listening to new one.
            model = newModel;
        }

        // Removes all current columns including the hidden ones.
        // For visible columns that are removed, TableColumnModelEvents get fired.
        while (!allTableColumns.isEmpty()) {
            removeColumn(allTableColumns.elementAt(0));
        }

        // Create new columns from the data model info
        for (int modelColumnIndex = 0; modelColumnIndex < newModel.getColumnCount(); modelColumnIndex++) {
            TableColumn newColumn = new TableColumn(modelColumnIndex);
            String columnName = newModel.getColumnName(modelColumnIndex);
            newColumn.setHeaderValue(columnName);
            addColumn(newColumn);
        }
    }
public void createColumnsFromModel(TableModel newModel) {
        if (newModel != model) {
            if (model != null) {
                model.removeTableModelListener(this);  // Stop listening to old model.
            }

            newModel.addTableModelListener(this);  // Start listening to new one.
            model = newModel;
        }

        // Removes all current columns including the hidden ones.
        // For visible columns that are removed, TableColumnModelEvents get fired.
        while (!allTableColumns.isEmpty()) {
            removeColumn(allTableColumns.elementAt(0));
        }

        // Create new columns from the data model info
        for (int modelColumnIndex = 0; modelColumnIndex < newModel.getColumnCount(); modelColumnIndex++) {
            TableColumn newColumn = new TableColumn(modelColumnIndex);
            String columnName = newModel.getColumnName(modelColumnIndex);
            newColumn.setHeaderValue(columnName);
            addColumn(newColumn);
        }
    }
public void createColumnsFromModel ( TableModel newModel ) { if ( newModel != model ) { if ( model != null ) { model . removeTableModelListener ( this ) ; // Stop listening to old model. } newModel . addTableModelListener ( this ) ; // Start listening to new one. model = newModel ; } // Removes all current columns including the hidden ones. // For visible columns that are removed, TableColumnModelEvents get fired. while ( ! allTableColumns . isEmpty ( ) ) { removeColumn ( allTableColumns . elementAt ( 0 ) ) ; } // Create new columns from the data model info for ( int modelColumnIndex = 0 ; modelColumnIndex < newModel . getColumnCount ( ) ; modelColumnIndex ++ ) { TableColumn newColumn = new TableColumn ( modelColumnIndex ) ; String columnName = newModel . getColumnName ( modelColumnIndex ) ; newColumn . setHeaderValue ( columnName ) ; addColumn ( newColumn ) ; } }
Adapted from JTable.createDefaultColumnsFromModel().
Adapted from JTable . createDefaultColumnsFromModel () .