> Dear Java programmers,
>
> How can i align text displayed in a JTable.
>
> By default the text is left alignend, but i want the text to be right
> aligned...
By default, if your value inside table cell is String it will be left
aligned, if it is Number (Integer, long, Float, Double) it will be right
aligned. Thats because JTable's default renderers render values that way. If
you want to overide this default bahaviour you have to implement your own
TableCellRenderers, for exapmle string renderer. When you write it, register
that renderer to String.class. Besides alignment, you can change font color,
style etc.
Try to find some tuorials about implementing custom renderers for JTable on
sun.java.com
Data is visualized through renderers. Check API for TableCellRenderer
and its detault implementation DefaultTableCellRenderer in
javax.swing.table package.
You will need to create your own subclass to customize dsplay
HTH
Mike
Arnoud - 16 Jan 2004 08:40 GMT
Thanks... It worked fine :-D