*
The moose likes Swing / AWT / SWT and the fly likes How align data columns in a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How align data columns in a JTable" Watch "How align data columns in a JTable" New topic
Author

How align data columns in a JTable

Flavio Nobili
Ranch Hand

Joined: Jan 28, 2004
Posts: 58
Hi to all,
How can I change the alignment of a data column in a JTable?

Regards,
Fl�vio.


Java Developer
SCJP, SCJD, SCWCD, SCBCD
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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 ]

SCJP2. Please Indent your code using UBB Code
Flavio Nobili
Ranch Hand

Joined: Jan 28, 2004
Posts: 58
Thanks Jose for your help.
It worked fine.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
By the way there is no need of subclassing. Instantiate a DefaultTableCellRenderer, set its alignment and assign it to several TableColumns.
 
 
subject: How align data columns in a JTable
 
Similar Threads
JTable
jtable
jtable
JTABLE
JTable