Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable columns widths reset after model change  RSS feed

 
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: 2787
12
  • 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!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!