• 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

Background Pattern for a Cell in JTable

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pomchi,

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



-Nate
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Nate!!
It worked!
-Pomchi
reply
    Bookmark Topic Watch Topic
  • New Topic