Your cell renderer is, by default, an extension of JLabel. Change the horizontal alignment of the renderer you use for each column you want different alignment for. You can also add a $ dollar sign in front of any data before it is painted by the cell renderer. ------------------ Matthew Robinson co-author of "Swing" (1999, Manning Publications). Freely available at http://www.spindoczine.com/sbe
Matthew Robinson<BR>firstname.lastname@example.org<BR>co-author of "<a href=http://www.amazon.com/exec/obidos/ASIN/189311578X/ref=ase_electricporkchop/107-7882751-0234939 target=newwindow rel="nofollow">Swing</a>" (1999, Manning Publications). Freely available at <A HREF="http://www.spindoczine.com/sbe" TARGET=_blank rel="nofollow">http://www.spindoczine.com/sbe</A>
Joined: Apr 30, 2001
Just make sure not to add the $ to the real data stored in your table model... only use it for rendering purposes ------------------ Matthew Robinson co-author of "Swing" (1999, Manning Publications). Freely available at http://www.spindoczine.com/sbe
Hello Matt, I had the same problem. Actually I am using JClass software for sortable tables. I am sending in a DefaultTablemodel into a JCSortableTable (this extends JTable). I have boolean values(check boxes) in my data. Now when the table is displayed my check box column is left-aligned. I want that to be center-aligned. I tried to the following code but it gave me a class cast exception. JCSortableTable table = new JCSortableTable(DefaultTableModel TM) Class ck = table.getColumnClass(4); table.getDefaultRenderer(ck).setHorizontalAlignment(SwingConstants.CENTER); doesnt work this way b'cos getDefaultRenderer(..) returns a TableCellRenderer interface and not DefaultTableCellRenderer object... how do i do that thanks for ur help..
Hi Jay, I had the same problem. In your rendering class, you should create a panel and add to it whatever you like. Then return ther panel as your returning component. Let me know how things go. Brian SCJ2P
Please re-register with usernames that follow the JavaRanch UserName Guidelines. Your usernames have to be in the form "First Name" + space + "Last Name", where first and last names are longer than one character, and where user names are not obviously fake.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.