This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTable - how to set background color Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable - how to set background color" Watch "JTable - how to set background color" New topic
Author

JTable - how to set background color

Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
I've got a JTable inside a JScrollPane in the main window of my application. Say I add 2 rows to my table the background color is white for those 2 rows but for the rest of my table the background color is gray. How can I set the background color so that the background is white? I've tried setBackground(Color.white) but that doesn't make the gray part white.
Any suggestions?
Thanks,
Frank

[This message has been edited by Frank Hale (edited May 31, 2000).]
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
I figured it out. All I needed to do was get the JViewport of the JScrollPane my JTable was in and set its background color.
Frank
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
Thanks for posting your solution. I was trying to do this for an hour before I searched JavaRanch and found it.
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
No problem.
I try to always post a solution to a question I ask if I figure it out before somebody helps me.
Take care! Have fun!
Brian Snyder
Greenhorn

Joined: Apr 24, 2002
Posts: 16
Just did a search and glad you had this here. NICE! So simple, but yet so simple.
Yuan Ye
Ranch Hand

Joined: Mar 05, 2003
Posts: 172
Thanks for the solution, I have spent 2 hours on that problem. glad now.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTable - how to set background color