Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

removing columns from a JTable

843804Oct 26 2004 — edited Nov 4 2004
Hi

I am looking to remove columns from the view of a table using
javax.swing.table.TableColumn col = jTable1.getColumnModel().getColumn(1);
jTable1.removeColumn(col);
however, i still want to be able to reference this column later on. I was hoping that
table.getColumnModel().getColumnCount();
would return the number of underlying columns (which is 4) but it only returns 3
However,
table.getModel().getColumnCount()]
does return 4 columns but I cannot get the column index from this call.

in effect i want to do
for (int columnIndex = 0; columnIndex < selectedColumnNames.size(); columnIndex++) {
        selectedColumnName = selectedColumnNames.get(columnIndex).toString();        
        modelIndex = table.getColumnModel().getColumnIndex(selectedColumnName);        
// (above) throws illeageArgumentException as the column is not found as the column model only has 3 out of the 4 columns
        row.add(table.getModel().getValueAt(rowIndex, modelIndex));             
}
But cannot think of a way using the (default) table model. I am using the basic tableModel as i have many different classes that have their own type of TableModel (ie extend TableModel, or implement cant remember just now) but this one (TableModel) is implemented by all.

Would appreciate any help

Many thanks
Rudy
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2004
Added on Oct 26 2004
8 comments
559 views