This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to wrap column name in swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to wrap column name in swing" Watch "How to wrap column name in swing" New topic

How to wrap column name in swing

rahul S Sharma

Joined: Jun 08, 2011
Posts: 21
Hi Folks,

I am fetching some data from database and showing it in jtable by using AbstractTableModel. Now the columns which I am fetching has some long description like 'Payment Method' is showing 'Payment Met...'. How can I wrap those column name . Please suggest me some solution.

Matthew Brown

Joined: Apr 06, 2010
Posts: 4544

You could try using HTML. I think JTables use JLabels as cell renderers by default, and they'll wrap HTML text, or let you put your own line breaks in. So try setting the column title to "<html>Payment<br>Method</html>"

Failing that, I think you need to supply your own TableCellRenderer, and use a component that will do what you want. You can change the renderer for a single column by using table.getTableColumn(...).setHeaderRenderer(...), or for all the headers at once using table.getTableHeader().setDefaultRenderer(...).

See for more about using custom renderers in tables.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10836


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
I agree. Here's the link:
subject: How to wrap column name in swing
It's not a secret anymore!