This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to wrap column name in swing

 
rahul S Sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic