Right align column in JTable

I need to display text as right aligned for a column in a JTable. Suggestions
[91 byte] By [gil_e] at [2007-9-26 1:18:29]
# 1

You must to have the model, like next code:

TableColumnModel columnModel = tableView.getColumnModel();

TableColumn colorColumn = columnModel.getColumn(0); //get the desire column

DefaultTableCellRenderer colorColumnRenderer = new DefaultTableCellRenderer();

colorColumnRenderer.setForeground(Color.red); //to change the color

colorColumnRenderer.setBackground(Color.gray);

colorColumnRenderer.setHorizontalAlignment(JLabel.RIGHT); //here you aling...

colorColumn.setCellRenderer(colorColumnRenderer);

When the cell is editing if you want the same aling also you must to define the aligned like that

JTextField texto= new JTextField();

texto.setHorizontalAlignment(JTextField.RIGHT);

colorColumn.setCellEditor(new customEditor(texto));

This works for me...

pedro.garcia at 2007-6-29 0:49:34 > top of Java-index,Archived Forums,Swing...
# 2
Thanks...that did the trick.
gil_e at 2007-6-29 0:49:34 > top of Java-index,Archived Forums,Swing...