Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

JTable, aligning text

Thread view: 
Arnoud - 15 Jan 2004 08:00 GMT
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...

Thanks in advance,

Yours

Arnoud
Igor Buzatovic - 15 Jan 2004 08:52 GMT
> 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
Mike Grigorov - 15 Jan 2004 12:16 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.