You never initialize or use your PropertyChangeSupport object. You should
- Change your PropertyChangeSupport variable to a SwingPropertyChangeSupport variable since this is Swing that you're working with, and you thus want all notifications done on the EDT, the Swing event thread.
- Initialize PropertyChangeSupport object and pass into its constructor
this
, the current object. - Give your class both an
addPropertyChangeListener(PropertyChangeListener listener)
and aremovePropertyChangeListener(PropertyChangeListener listener)
method, so that other classes can add listeners and listen for changes. - In the above methods, add or remove the listener to your support object.
- You should fire the support object in one or more
setXXX(...)
methods to notify the listeners of the changes, passing in the appropriate property name and old and new values. - Note that if your class extends a Swing component, it already has PropertyChange support. Check the API, including the
addPropertyChangeListener
andremovePropertyChangeListener
methods. - Having said that, you will almost never want to extend JFrame.
- You should read the tutorials on this for they are to be found with just a little searching (the link above was the first hit on a
PropertyChangeListener tutorial
Google search).
For example, please have a look at the code here:
- how to trigger an action in parent JPanel when a component in a child JPanel is updated (Java Swing): this uses the innate property change support that Swing components have.
- Using a JFileChooser with Swing GUI classes and listeners: and this uses its own SwingPropertyChangeSupport object to make the code more MVC compliant.