• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with JTable.doLayout()  RSS feed

 
Nick De Graeve
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to extend JTable so I can have weighted column widths. To do so I have overridden JTable.doLayout() . It works perfect except the program flow never reaches setValue() of the table model and I can't understand why not.

Can any of you shed some light on this?

Thanks.

Test program:
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nick De Graeve:
It works perfect except the program flow never reaches setValue() of the table model and I can't understand why not.


I think you should be able to get to setValue if you click once in a cell and start typing.

But I think double clicks will cause revalidation, which calls your doLayout, which is interfering with things. Your doLayout probably shouldn't be messing with the columns if the size hasn't changed. Try something like:

if (getColumnModel().getTotalColumnWidth() == getWidth()) return;
 
Nick De Graeve
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your doLayout probably shouldn't be messing with the columns if the size hasn't changed. Try something like:

if (getColumnModel().getTotalColumnWidth() == getWidth()) return;


You were right! That fixed it. Thanks.

I also found another small bug: if I resized the columns myself and then resize the frame, the columns are laid out as defined by the weights. That's not right so I added a check that when the column widths are user defined, I'll use default layout. Better would be to also resize the columns using the weights, but the added value would be limited and I don't have the time to study it.

So the complete table looks like this:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!