This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable columns widths reset after model change

 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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!
 
Rob Camick
Ranch Hand
Posts: 2539
9
  • Likes 3
  • Mark post as helpful
  • send pies
  • 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: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Rancher!

Works like a charm!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic