Both ActionListener and ItemListener are used to fire an event with JCheckBox?
So, what's the difference between them and in which case one of them is preferred to the other?
Both ItemListener
as well as ActionListener
, in case of JCheckBox
have the same behaviour.
However, major difference is ItemListener
can be triggered by calling the setSelected(true)
on the checkbox.
As a coding practice do not register both ItemListener
as well as ActionListener
with the JCheckBox
, in order to avoid inconsistency.