aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable columns widths reset after model change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable columns widths reset after model change" Watch "JTable columns widths reset after model change" New topic
Author

JTable columns widths reset after model change

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

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!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
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

Joined: Jul 13, 2010
Posts: 610

Thanks a lot Rancher!

Works like a charm!
 
 
subject: JTable columns widths reset after model change