wood burning stoves
The moose likes Swing / AWT / SWT and the fly likes JTable and cell aligning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable and cell aligning" Watch "JTable and cell aligning" New topic

JTable and cell aligning

Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
How do I right-align data in one of my JTable cells? I know that by default integer values are right aligned, but I have a string in my JTable representing an integer -- so can't use that. I read that I can use DefaultTableCellRenderer, I tried it, but it has no affect on my code. What am I doing wrong?
This is what I have:
model=new com.kwi.ChildOrdModel(model1);
ordbox=new JTable(model);
ordbox.setPreferredScrollableViewportSize(new Dimension(650,192));
DefaultTableCellRenderer Quantity = new DefaultTableCellRenderer();
TableColumnModel columns = ordbox.getColumnModel();
thanks in advance,

All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi Alex,
What's this Quantity variable?
try this:
MyCellRenderer extends JLabel implements TableCellRenderer
public Component getComponent(// args)
return this;
I've not tested this code. maybe something will be missing, but I hope it gives you an idea.
I agree. Here's the link: http://aspose.com/file-tools
subject: JTable and cell aligning
It's not a secret anymore!