I have read the docs for PropertyChange support and EventListenerList.
From my understanding, both serve similar purposes in holding a list of listeners
and notifying
them when event/propertyChange
occurs.
Is it only in case of GUI applications
, that EventListenerList
becomes handy?. For a simple JavaBean
application that does not use GUI components
, is there an advantage of using one over the other.

- 109,525
- 20
- 134
- 319

- 30,124
- 69
- 225
- 393
-
depends on your goal, real requirements and your skill,I'm never tried to sync EDT with/from events stored in EventListenerList programatically, no reason – mKorbel Mar 10 '14 at 20:03
-
@mKorbel: can you please elaborate? – brain storm Mar 10 '14 at 20:06
-
For a simple JavaBean application that does not use GUI components - looks like as nonsence for me (1st. sight), there is/aren't specific point(s) for discusion, nor elaborating, both themes are about top_level skills and good practicies for apps with GUI, there EventListenerList should be used as control mechanism for various events (not as source for fireXxxEvent to EDT) – mKorbel Mar 10 '14 at 20:10
2 Answers
Generally speaking, a PropertyChangeEvent
occurs when some property value of the object changes (a property/value which you can read), where a (general) event could describe any kind of event (such as a change in selection or a mouse click), it doesn't have to represent a change in the state of the object
PropertyChangeSupport
is part of the bean framework (in particular, but not limited to) GUI editors. This doesn't mean you can't use it, in fact, many objects rely on this functionality, such as SwingWorker
and many of the objects from SwingLabs for example.
With that in mind, you should use ProperyChangeSupport
when you want to notify interested parties that a property/value of an object changes and EventListenerList
when you want to provide general event notification for things that are occurring within the object (but don't have to be related to a specific property or state)
The only issue I have with ProptertyChanegSupport
, is it can less obvious which properties are bound and which aren't, sometimes making it difficult to get started with new objects, where as it's reasonably easy to look up all the "addListener" methods, but that's just me
While I'm sure the original intention of the EventListenrerList
was for GUIs, I've used them for non-GUI work before, but you might find it easier to to use a List
if you only have support for a single listener though, just saying

- 343,457
- 22
- 230
- 366
-
is there a place where using `PropertyChangeSupport` will just not work and you have to use `EventListenerList`? – brain storm Mar 10 '14 at 22:03
-
Plenty, look at the `MouseListener`. There is no "mouse" object which has properties which are changed. Components which use a `MouseListener` don't "have" to change their state in response to a mouse event, but provide event notification when a mouse event occurs. `ActionListener` on a `JTextField` or `JButton` for example. Either (directly) changes the state of the components, but provide pure event notification. A generalised listener is generally easier to deal with then `PropertyListener`s, as they have dedicated methods that provide information about the event that occurred. – MadProgrammer Mar 10 '14 at 22:59
as PropertyChangeListener is just a specific "subclass" (extending interface) of EventListener - which is a marker interface and defines no methods, it is much easier to work with PropertyChangeSupport than EventListenerList - that is because if you start off with an EventListenerList you'll need to always do instanceof checks and casting to get to the actual "business" methods of your listeners (since the interface they all implement has no methods)

- 23,949
- 10
- 71
- 115