This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Background Pattern for a Cell in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Background Pattern for a Cell in JTable" Watch "Background Pattern for a Cell in JTable" New topic
Author

Background Pattern for a Cell in JTable

Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
Hi,
I need to set some kind of background pattern (like dots,cross) for cells that are inactive.I was using lightGray color to do the same......but I want to color those cells and wish to have a different background to show that these are disabled.
Any suggestions are welcome.
Thanks
Pomchi
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
You'll need to create a custom TableCellRenderer and install on your table columns so that you can override the cell component's paint() method to do your custom background pattern drawing.
Rob


Rob
SCJP 1.4
Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
Hi Rob,
I know that this is how I can put an icon in the cell.But I want my pattern to occupy the entire cell space.It should increase or decrease with the cell width.
Any example related to this would help.
Thanks
Pomchi
[ January 09, 2002: Message edited by: Pomchi Bedi ]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Pomchi,

Here's a quick example to do what you want... look especially at the PatternRenderer class... that defines the behaivior you want...



-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
Hi Nate,
Thanks so much for your help.
But I have one more problem.All my rows have different background colors and in each row there are a few cells that are inactive/disabled.I want the background color of those inactive cells to be the same as the other ones in the row but along with the background color I want the background pattern to appear for the diasbled cells.
That means I want to change the background of the imageIcon I am rendering.Is it possible??
Thanks & Regards
Pomchi
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

If you use images for your ImageIcons that support transparency (like Gifs) then yes, you can... you'll also need to call super.paintComponent( g ) in the first line of your PatternRenderer paintComponent() method. If you don't want to make image files, you can always just extend Icon and draw the image you need in it's paintIcon() method...

-Nate
Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
Thanks a lot Nate!!
It worked!
-Pomchi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Background Pattern for a Cell in JTable
 
Similar Threads
hi
HSSF Default Color Problem
CSS : Cell borders showing up on th cells but not td
Overriding CSS styles using JS
jQuery doubt with reference to Object Literal Example.