Remove and add columnn (Jtable) help needed.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Cherlyn_Loh
Posted On:   Thursday, October 4, 2001 01:04 AM

I have a JTable which I need to remove and add column. My remove column code is : DefaultTableColumnModel columnMod; columnMod.removeColumn(columnMod.getColumn(1)); My add column code is : DefaultTableModel tableMod; tableMod.addColumn("three"); My problem is : say my table has 2 columns initially "one" "two" after removeColumn(), the column will disappear from the JTable. like this "one" but when I addColumn() later, the removed column will appear again. like this "one" "two" "three"    More>>

I have a JTable which I need to remove and add column.



My remove column code is :



DefaultTableColumnModel columnMod;

columnMod.removeColumn(columnMod.getColumn(1));



My add column code is :



DefaultTableModel tableMod;

tableMod.addColumn("three");



My problem is :
say my table has 2 columns initially

"one" "two"

after removeColumn(), the column will disappear from the JTable. like this

"one"

but when I addColumn() later, the removed column will appear again. like this

"one" "two" "three"


I think the problem is DefaultTableColumnModel is used to removeColumn but DefaultTableModel is used to addColumn, resulted in some kind of discrepancy, how to go about this? Any help appreciated.

   <<Less

Re: Remove and add columnn (Jtable) help needed.

Posted By:   Shai_Almog  
Posted On:   Friday, October 5, 2001 04:57 AM


Don't use the table column model! While you can get it to work, its a complicated model.




In order to remove a column you simply need to modify the TableModel so it won't return it. If you don't want to modify the model simply use a proxy/decorator pattern to hide the column by implementing a layered model. Don't forget to fire a table model change event whenever you change the table model!

About | Sitemap | Contact