[ACCEPTED]-JCheckbox change listener gets notified of mouse over events-listener
You get events on mouse over as focus gained/lost 12 represents a change to the state of the 11 component.
Instead you could use an ItemListener 10 which will give you ItemEvents.
The object 9 that implements the ItemListener interface 8 gets this ItemEvent when the event occurs. The 7 listener is spared the details of processing 6 individual mouse movements and mouse clicks, and 5 can instead process a "meaningful" (semantic) event 4 like "item selected" or "item deselected".
You 3 can add it to your checkbox with the addItemListener() method 2 in the AbstractButton class. Just replace 1 addChangeListener with this:
c.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
System.err.println(e.getStateChange());
}
});
Use c.setRolloverEnabled(false
)` and you won't get any event for mouse 1 motions.
The state of the check box (even just the 7 check box model) changes depending upon 6 whether it has the mouse over it or not. So 5 a state change event should be expected.
So, just 4 check back to see what state the check box 3 is in and update accordingly. It is better 2 to go straight for the model, rather than 1 using the "bloated" component interface.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.