• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JTable and cell aligning

 
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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();
Quantity.setHorizontalAlignment(SwingConstants.RIGHT);
TableColumnModel columns = ordbox.getColumnModel();
columns.getColumn(2).setCellRenderer(Quantity);
thanks in advance,
Alex
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Alex,
What's this Quantity variable?
try this:
MyCellRenderer extends JLabel implements TableCellRenderer
{
public Component getComponent(// args)
{
this.setHorizontalAlignment(SwingConstants.RIGHT);
return this;
}
}
I've not tested this code. maybe something will be missing, but I hope it gives you an idea.
chantal
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic