How to you align/justify JTable column header text?

Many times we need to align the JTable header text. Doing this is a simple , you just need to get getDefaultRenderer from the table header.

From this renderer you can get the JLabel component on which you can do the alignment as follows :


TableCellRenderer rendererFromHeader = table().getTableHeader().getDefaultRenderer();
JLabel headerLabel = (JLabel)rendererFromHeader;
label.setHorizontalAlignment(JLabel.LEFT); // Here you can set the alignment you want.
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

3 comments:

  1. WOW just what I was searching for. Came here by searching for tablecellrenderer

    ReplyDelete
  2. Nice....This was very helpful. Thank you very much :)

    ReplyDelete
  3. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete