File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Background Pattern for a Cell in JTable

 
Pomchi Bedi
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Rob Ross
Bartender
Posts: 2205
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Nate!!
It worked!
-Pomchi
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic