• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable dynamic column problem

 
swathi bog
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to add one new column dynamically to already exsiting table.
Please help me.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create a TableColumn, give it a header value, then add it to the table header's column model
 
swathi bog
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply.I wnated to add the column at 0th index.(as first column)
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read the apidocs - its all there
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Swathi Swathi",
Please check your private messages for an important administrative matter.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding a TableColumn only works if the column already exists in your TableMode. If not, you have to add it there first, then add the TableColumn. Adding to the TableModel is not supported for all TableModels though. As far as I know, only DefaultTableModel supports that. And although you can only add it to the end of the columns, that doesn't matter - you can still add the TableColumn at a different location. After all, it is the view (JTable combined with TableColumn) that determines the viewing order, not the model. That's why JTable has a method to convert view column indexes to model column indexes and vice versa.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!