Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting JTable columns

 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • 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,
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3817
10
  • Mark post as helpful
  • send pies
  • 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
 
olivier roussille
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 3817
10
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic