aspose file tools*
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 JavaScript Promises Essentials this week in the JavaScript 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
Author

How to wrap column name in swing

rahul S Sharma
Greenhorn

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.

regards......
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4457
    
    8

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 http://download.oracle.com/javase/tutorial/uiswing/components/table.html#renderer for more about using custom renderers in tables.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

Try


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to wrap column name in swing