• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

changing headers on JTable caused other problems

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I'm working with a JTable which sets up certain columns with cell renderers and editors. My application allows the user to change the interface to a different language, so JMenuItems, buttons, etc. change their text and I've set it up so that the header on the JTable changes as well. Two lines of code make that happen:



All this part works as expected, however, after the call to fireTableStructureChanged() has completed, the columns that were governed by cell renderers and editors are no longer in effect. Those cells have reverted back to working as normal JLabel cells. What happened? How do I prevent losing the renderers and editors on those columns?

See below for additional code, which might help.

Alan

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the columns that were governed by cell renderers and editors are no longer in effect. Those cells have reverted back to working as normal JLabel cells.



When the fireTableStructureChaged() event occurs, the TableColumnModel is rebuilt, which reacreates all the TableColumns, so you lose the renderers/editors/ that you previously added.

How do I prevent losing the renderers and editors on those columns?



Don't invoke the fireTableStructureChanged() method. Instead update your TableColumns of the TableColumnManger manually. You can use the setHeaderValue() method to update the header text. You will then need to invoke repaint() on the table header.
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I'll give that a try.

Alan
 
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic