• 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 columns widths reset after model change

 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy Ranchers!

The original question was posted in the SCJD forum here, but I will shortly explain what the problem is.

I've noticed that if I set the column widths using:



initially, the table has the column widths as I wanted. Apparently after the model is changed using



it resets the column widths to initial values (all columns uniformly distributed). It also happens if the columns were changed by the user - after he hits the "search" button (the model is changed) and the column widths are reset to the default.

How can this problem be solved?

Thanks in advance!

Cheers!
 
Rancher
Posts: 3324
32
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you reset the model the fireTableStructureChanged() method is invoked. The table responds by recreating the TableColumnModel, which in turn recreates all the TableColumns.

Assuming your structure is the same and only the data changes then you can avoid this by using:



after you create the table with data the first time.
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Rancher!

Works like a charm!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic