• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable column headings - how to change AFTER JTable instantiation

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic