• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic generation of columns required in JTable.

 
Dinesh Ramaswamy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In JTable,I want to dynamically generate my columns.I would very much appreciate if anyone can help me in this regard.
Regards,
Dinesh.
 
ravindran shanmugam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Define an instance of JTableHeader as class level variable.
eg.

2. Define an instance of TableColumnModel as class level variable.
eg.


3. After creating the table, call getTableTeader on the JTable instance ( say jt) and set the value to jTableHeader.
eg.

4. Call getColumnModel method on jTableHeader instance and set the value to tableColumnModel
eg.

say you want to add a column on button Click,
add the following code in actionPerformed method
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!