Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

In this lesson I want to show how other components can be notified of a bean's impending property changes.

Inside the bean we seek the assistance of PropertyChangeSupport.

The component to be notified, btwo, is registered in the bean's ...

addListener-method with PropertyChangeSupport, pcs .

btwo implements PropertyChangeListener.

BeanOne also contains a VetoableChangeSupport,...

so another component can be registered as one able to veto a proposed change.

ListenUp implements VetoableChangeListener.

It can veto by throwing such an exception.

When the BeanUser attempts to change the bean's property,...

the potential vetoers are notified first.

When one of them vetoes, the method continues in the catch.

This vetoer doesn't take kindly to a proposed value belower 120.

If there are no vetos at all, the regular change listeners are notified,...

before the bean's property effectively changes.

The listener is itself another bean with a color property, that has its Green and Blue colour values set to the first bean's property new value.

These listeners are only interested in BeanOne's 'prop' property.

======

This bean's property ...

is said to be BOUND ( to BeanTwo ) ...

and CONSTRAINED ( by ListenUp ).

======

The techniques shown sofar can be applied to ANY component, but, for visual beans, those derived from (J)Component,...

it's actually a lot easier, because with them, you don't need the Support classes and add/remove methods.

They inherit the firePropertyChange and add/remove..Listener methods from the (J)Component class,...

so a call like this could be made easily, to notify listeners that were registered beforehand by means of the inherited addListener method.

So, if it weren't for your educational benefit, with BeanOne we could have saved us a lot of fuss, because it is visual, it derives from JPanel, which derives from (J)Component. ======

======

NOTES

======

For notification of certain property changes only, to register listeners for those properties, we could use this ( inherited or added ) method.