Sending Change Events in Swing
Swing actually uses two different
change event classes. The first is the standard
java.beans.PropertyChangeEvent
class. This class passes a reference to
the object, sending the change notification, as well as the property
name, its old value, and its new value. The second, javax. swing.event.ChangeEvent, is a lighter version that only
passes a reference to the sending object—in other words, the
name of the property that changed, as well as the old and new values,
are omitted.
Note
Since the ChangeEvent class
is not part of the JavaBeans specifications, properties that use this
event are not “bound” according to the JavaBeans
standard. In order to prevent confusion, properties that use a
ChangeEvent to notify listeners of property
changes have not been marked as bound in our property tables.
Because the ChangeEvent only includes a reference
to the event originator, which never changes, you can always define a
single, static ChangeEvent and reuse it over and
over when firing events from your component.
The ChangeEvent Class
The ChangeEvent is a stripped-down version of the
java.beans.PropertyChangeEvent class. This class
has no methods or properties, only a constructor:
Constructor
- public ChangeEvent(Object source)
The constructor for the
ChangeEventclass. It takes only a single object, which represents the entity sending the event.
The ChangeEvent class extends the
java.util.EventObject class. This object contains
the getSource() method, which you can ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access