File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable columns widths reset after model change

 
Piotr Nowicki
Ranch Hand
Posts: 610
IntelliJ IDE Java Linux
  • 0
  • 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: 2475
8
  • 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: 610
IntelliJ IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Rancher!

Works like a charm!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic