Search code examples
javajtablejcheckbox

Notification when a checkbox in a JTable is checked


I've searched for this for quite a while and haven't found a clear example anywhere. I'm a Java newbee using NetBeans. I have a boolean value in the first column of a JTable (called "Enabled") and I have some plugin code that I need to call to see if it has the settings it needs in order to be enabled, and if not, display a message box and prevent Enabled from being checked.

All I really need is for a function to be called when the checkbox is checked and I can take it from there. Does anyone have an example of how to do this?

Thanks for your help!

Harry


Solution

  • You probably want a TableModelListener, as discussed in Listening for Data Changes. Alternatively, you can use a custom editor, as discussed in Concepts: Editors and Renderers and the following section.