Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable column widths reset on refresh

 
Steve Smith
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have noticed this problem in both my application and in the application in Max's book. If you resize some JTable columns and then do a search, the column widths revert back to their defaults. I am using an MVC implementation, where all of the controller's methods return a new table model to the view. How can this be fixed?
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve
You can get the size you need from your schema, or at least base it on the max length of the columns, I multiplied that by 3 which fits perfectly.
To actually set the column sizes you'll need to run through the ColumnModel's which you get from the JTable. Then have a look at TableColumn where you can set the preferred width.
I can't recall that it will be fixed and I doubt it would, what it should do is default to appropriate sizes and perhaps negate the need to fiddle with the column to begin with.
HTH
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost forgot, had another squizz at my code and I see that I called that method to setup the sizes every time the JTable is given some data, so I definately ignored the user's changes which is probably what you're trying to avoid.
 
Steve Smith
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response Ta Ri Ki Sun. Really I am just worried that this might be something I will lose marks for, as thats really what it all comes down to isnt it? I would be interested to know if anyone got full GUI marks with this limitation. Maybe I can somehow get a list of the column widths before assigning a new table model and then reinstate them?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic