File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How align data columns in a JTable

 
Flavio Nobili
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,
How can I change the alignment of a data column in a JTable?

Regards,
Fl�vio.
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taking advantage of the fact that DefaultTableCellRenderer extends JLabel.

One approach is creating as many renderers as alignments you need. For instance the renderer providing right one:

Then you could assign such instance to any TableColumn needing right alignment: aTableColumn.setRenderer(aRightTableCellRenderer)
[ March 02, 2004: Message edited by: Jose Botella ]
 
Flavio Nobili
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jose for your help.
It worked fine.
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way there is no need of subclassing. Instantiate a DefaultTableCellRenderer, set its alignment and assign it to several TableColumns.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic