• Post Reply Bookmark Topic Watch Topic
  • New Topic

changing JTable cell's background onClick

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • 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
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
thanks! Will try that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!