Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to adjust the alignment of Jtable cells(data) from left to right...?

843807Jan 27 2010 — edited Jan 27 2010
Hi everybody:
I use this code for adjust the alignment of the cells in JTable from left to right but I got nothing.
I don't know if there is something wrong in the code or I use a wrong way for do it...!!?
I hope you help me.
This is the code
public class RightTableCellRenderer extends DefaultTableCellRenderer{
	
	public RightTableCellRenderer() {
		setHorizontalAlignment(JLabel.RIGHT);
	}
}

public class JoTable extends JTable {

	public JoTable() {
		setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
		setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		setTableCellAligment(JLabel.CENTER);
		updateUI();
	}

	public void setTableCellAligment(int alignment) {
		RightTableCellRenderer cellRenderer = new RightTableCellRenderer();
		for (int i = 0; i < getColumnCount(); i++) {
			this.setDefaultRenderer(getColumnClass(i), cellRenderer);
		}
	}
}
Then I use the JoTable in other class and fill it with data but the data still left alignment....?
Please help me
Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 24 2010
Added on Jan 27 2010
5 comments
1,326 views