• Post Reply Bookmark Topic Watch Topic
  • New Topic

store JTable columns size on add row

 
tatae alvostru
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I add a new row into JTable it resizes my columns widths. How can I keep the columns from resizing ?
 
eric moon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it's sure not as easy as it seems, as far as I can tell. The reason the columns all get reset is that when you add or delete columns fireTableStructureChanged() gets called. This in turn calls createDefaultColumnsFromModel(). So one way to do it is to override createDefaultColumnsFromModel(). Problem is, that method gets called when the table is created, so your constructor won't work right. So you'll have to put the existing code of createDefaultColumns into your constructor. You now have a problem where the columns get de-synchronized from your view. I got that fixed somehow, but I eventually gave up on the whole thing.
Let me know if you get something working. Hopefully this is a start.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!