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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply 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: 3793
    
    1

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: 8436

Try


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to wrap column name in swing
 
Similar Threads
EJB returning dialect characters
Dealing with two JOptionPanes????
Header Wrap
Images using Ajax
Can I start threads to access ejb's in parallel