File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes in a JTable, changing column header text alignment for specific columns only Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "in a JTable, changing column header text alignment for specific columns only" Watch "in a JTable, changing column header text alignment for specific columns only" New topic
Author

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

Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

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

Joined: May 03, 2008
Posts: 4664
    
    5

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.)


luck, db
There are no new questions, but there may be new answers.
Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

Thank you for the idea, I will give it a shot!
Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: in a JTable, changing column header text alignment for specific columns only