Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JTable.removeColumn() only hide?!

269 views
Skip to first unread message

Zsolt Zsoldos

unread,
Dec 10, 1998, 3:00:00 AM12/10/98
to
Hi Folks,

I am trying to use a JTable with dynamic addition/removal
of columns per user request. The problem is, if I remove
some columns either by JTable or DefaultTableColumnModel
removeColumn() call, the next time I add a new one, the
removed ones reappear! The documentation page at

http://java.sun.com/products/jfc/swingdoc-api-1.0.3/com/sun/java/swing/JTable.html#removeColumn(com.sun.java.swing.table.TableColumn)

says it explicitly:

Removes aColumn from the JTable's array of columns.
Note: this method does not remove the column of data
from the model it just removes the TableColumn
that was displaying it.

So, what can I do if I *REALY* want to remove a column
not just hide it? Is there any way?
Also, if a column is hidden by the so called 'remove'
calls, how can I show them again or control their state,
i.e. hidden/shown?

Thanks for any help in advance!

Zsolt

Charles Ballance

unread,
Dec 14, 1998, 3:00:00 AM12/14/98
to
Remove the column from the JTable's data model as well as the visual.

Steven C. Bond

unread,
Dec 15, 1998, 3:00:00 AM12/15/98
to
Yup, you're right. DefaultTableColumnModel.removeColumn() does not really
remove the column. The only way to truly remove the column is to use
DefaultTableModel.setDataVector(). DefaultTableColumnModel manages
an array of TableColumns (the attributes of the columns, not the data).
There
is no coordination between the DefaultTableColumnModel.removeColumn() and
the DefaultTableModel. This makes the code in Matthew Nelson's book
"Java Foundation Classes" (pages280-281) incorrect too.

I have submitted an RFE on this.

Steve

Charles Ballance wrote in message <3675CE6E...@webforged.com>...

Sona

unread,
Dec 16, 1998, 3:00:00 AM12/16/98
to Zsolt Zsoldos
Hi,

Actually removeColumn on the TableColumnModel will remove the specified column from the column model which is the table view but it will
still be there in the Table Model which is the table data.
Hence to remove column from just the view and add other columns..

first remove column on the tablecolumnmodel
then add columns to the table from the table model.
i hope this helps.
Sona

0 new messages