• 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

Formatting JTable columns

 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has anyone done other than the default left-justified columns? I'd like to center the airports, and right-justify and add dollar signs to the cost column. Cannot find a clear reference in the java.sun documentation...
Regards,
 
Enthuware Software Support
Posts: 4828
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need a component that implelments TableCellRendere, somthing like: class MyCellRenderer extends JLabel implements TableCellRenderer.
Read the Java Tutorial on JTable in Swing section. Customizing table cells is straight forward but customizing Headers is little bit more involved.
HTH,
Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

Your guide to SCJD exam!
www.enthuware.com/jdevplus
Try out the world's only WebCompiler!
www.jdiscuss.com
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I used a class extending JLabel and implementing cell renderer. It works BUT, if I do not implement it, there is no change of background color when the row of the JTable is selected. It remains a simple JLabel all the time.
So, in my renderer class, I would like to write:
if (isSelected == true){this.setBackground =Color.white;}
else {this.setBackground = Color.???}
"this" is the JLabel.
But how to get the appropriate color to highlight?On my computer,
the higlight color of the default renderer is a "Lavande" color, that is blue grey purple. Does the color remain the same on all the platform, PLAF, setting?
Or should I get a system property, a color model??? I can not find my answer in the API.
Thanks for your help
Olivier
 
Paul Anilprem
Enthuware Software Support
Posts: 4828
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just get the color using theTable.getSelectionForeground/Background()
HTH,
Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

Your guide to SCJD exam!
www.enthuware.com/jdevplus
Try out the world's only WebCompiler!
www.jdiscuss.com
 
You've gotta fight it! Don't give in! Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic