• 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

changing JTable cell's background onClick

 
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I have a JTable with JCheckBoxes as components in the cells. Is there a way to change cell's background when I click on a check box?
thanks,
Alex
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to write your own TableCellRenderer. It has to extend JCheckBox and implement the interface TableCellRenderer. It might be necessary to implement TableCellEditor as well (same procedure).
If you don't know how to do this, see the Swing Tutorial on TableCellRenderers.
chantal
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot:
It might not work to call jCheckBox.setBackground(Color). In this case try setting it opaque (jCheckBox.setOpaque(true)). If this fails as well, you will need to extend JPanel, put a JCheckBox on it and change the panels background.
cheers
Chantal
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks! Will try that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic