• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic