• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic