IntelliJ Java IDE
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Formatting JTable columns Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "Formatting JTable columns" Watch "Formatting JTable columns" New topic
Author

Formatting JTable columns

Douglas Kent
Ranch Hand

Joined: Oct 06, 2000
Posts: 171
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

Joined: Sep 23, 2000
Posts: 2547
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


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
olivier roussille
Greenhorn

Joined: May 02, 2001
Posts: 4
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

Joined: Sep 23, 2000
Posts: 2547
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
 
 
subject: Formatting JTable columns
 
Threads others viewed
How to find the length of the array
I passed SCJD :)
What is the meaning of data displayed by netstat -a
Is it ok to drop the foreign keys created by EJB 3 on the database?
Swing / JFC / AWT
MyEclipse, The Clear Choice