Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Left justifying gridbag cell with fill == BOTH  RSS feed

 
Brian McGuinness
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find JTable very irksome to use, since I almost always have to laboriously set the column widths to avoid having fields truncated, and it is very difficult to perform simple operations that people often find desirable, such as striping rows. So I decided to create my own table class that was easier to use rather than wasting any more time fighting with JTable. The basic idea is to use a gridbag layout to create a matrix of JLabels. This seems to work pretty well for the most part, but the problem is that when I set the fill to GridBagConstraints.BOTH I can't get the text in each data cell to be left justified; it keeps coming out centered. I would appreciate any help with this. My simplified table class is:



where GridBagPanel is a simple class that takes care of dealing with the GridBagConstraints (initializing fields to reasonable defaults) and lets me add components simply by invoking addComponent (x, y, width, height, component).

Thanks for the help.
 
Brian McGuinness
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I think I have this sorted out now. This seems to work pretty well:

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!