• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable column headings - how to change AFTER JTable instantiation  RSS feed

 
Randy Johnson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to change the column headings for a JTable that has already been instantiated? I have spent hours going over the API's for TableModel, TableColumnModel, etc., and just can't find a Class or method that will let me do it!
Any ideas?
Thanks
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The table model hast a method getColumnName() which returns the names of the columns whenever the JTable questions them. It will call this method especially after a TableStructureChanges event occured, which would be fired by the TableModel.
Thus, to change the column names (headers):
1. change the columns in the implementation of the
table model (you're free on that)
2. fireTableStructureChanged (that might not be the exact name, but it's something like that) in the table model.
3. the rest should happen automatically!
Chantal
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!