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 / February 2004

Tip: Looking for answers? Try searching our database.

How to center or right justify JTable column data?

Thread view: 
Jack - 03 Feb 2004 03:15 GMT
Probably a FAQ... but here goes...

How do I force all JTable column entries to be right aligned or center
aligned?  It appears the default is left aligned.

Thanks,

Jack
Flo - 03 Feb 2004 03:53 GMT
> Probably a FAQ... but here goes...
>
[quoted text clipped - 4 lines]
>
> Jack

Jack,

I beleive you will need to implement your own table model. The Java tutorial
at http://java.sun.com/docs/books/tutorial/uiswing/components/table.html is
what I read through to get around a similar problem. I created my own table
model and used a custom renderer.

class MyJLabelRenderer extends JLabel implements TableCellRenderer {

   // constructor
   MyJLabelRenderer() {
       this.setHorizontalAlignment(CENTER);
   }

   // returns component to use as renderer
   public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected, boolean hasFocus, int row, int col) {
       // could have some other logic in here...
       return this;
   }
}


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



©2008 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.