Text right-alignment in JTable

hi all

by default, the text/number in the grid in JTable are left-aligned.

How to make the text is left-alignment while number is right-alignment?

Rgds/Glogin
gloginAsked:
Who is Participating?
 
CEHJCommented:
You need to use a custom TableCellRenderer. See

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#colorRenderer

and set the alignment as the second line of objects' code shows
0
 
objectsCommented:
use a custom cell renderer for the column.

DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setHorizontalAlignment(SwingConstants.RIGHT);
0
 
CEHJCommented:
8-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.