Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

in a JTable, changing column header text alignment for specific columns only

 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

At what classes should one look at (research) when trying to change the alignment of the header text for a specific column in a JTable? I figured out how to change the entire JTableHeader text aligment through the getDefaultRenderer(), but I cannot figure out how to make certain column headers to be aligned left, while others are right. Any help would be appreciated.

Greg
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're ok with relying on implementation detail, you can wrap the table header's default renderer something likeOnly tested under MetalLookAndFeel. Use the idea at your own risk.

edit Should have mentioned clearly that the implementation detail this relies on is that a table header's default renderer (like most default cell renderers) extends JLabel.

Another approach independent of implementation detail is to use my Default Table Header Cell Renderer class. (The class doesn't respect custom foreground/background settings on the table header, but that's a 3-line fix if you need it.)
 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the idea, I will give it a shot!
 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, that is exactly it!!! Im using the system's default lookandfeel, so, as you pointed out, it is not garunteed to work 100% of the`time, but i would think it would work for most. Thanks!

Greg
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic