I have a Jlabel and a checkbox. I want to make it so that I can click on the Jlabel and the checkbox will be ticked. I need it to be a label because I use it for something else. Normally what I do is to just have a checkbox only with some text, but this time I need a label and checkbox, and I need the label to tick the checkbox when clicked upon. Below is the code I have. I have tried to add an action listener to the label but i get an error saying its an undefined type. Thank you...
JCheckBox _mycheckbox = new JCheckBox();
JLabel _mylabel = new JLabel(_mylabel);
You can consider adding a
MouseListener
to your JLabel and override themouseClicked()
method.