モジュール java.desktop
パッケージ java.beans

クラスPropertyChangeSupport

java.lang.Object
java.beans.PropertyChangeSupport
すべての実装されたインタフェース:
Serializable
直系の既知のサブクラス:
SwingPropertyChangeSupport

public class PropertyChangeSupport extends Object implements Serializable
バウンド・プロパティをサポートするBeanで使用できるユーティリティ・クラスです。 リスナーのリストを管理し、PropertyChangeEventをそれらにディスパッチします。 このクラスのインスタンスをBeanのメンバー・フィールドとして使用し、こうした種類の処理をそれに委譲できます。 PropertyChangeListenerは、すべてのプロパティまたは名前で指定されたプロパティに対して登録できます。

次に、JavaBeans仕様に記載されているルールおよび推奨事項に従ったPropertyChangeSupportの使用例を示します:

 public class MyBean {
     private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);

     public void addPropertyChangeListener(PropertyChangeListener listener) {
         this.pcs.addPropertyChangeListener(listener);
     }

     public void removePropertyChangeListener(PropertyChangeListener listener) {
         this.pcs.removePropertyChangeListener(listener);
     }

     private String value;

     public String getValue() {
         return this.value;
     }

     public void setValue(String newValue) {
         String oldValue = this.value;
         this.value = newValue;
         this.pcs.firePropertyChange("value", oldValue, newValue);
     }

     [...]
 }
 

PropertyChangeSupportインスタンスはスレッドセーフです。

このクラスは直列化可能です。 直列化した場合、直列化可能なリスナーが保存および復元されます。 直列化の際、直列化可能でないリスナーはスキップされます。

導入されたバージョン:
1.1
関連項目: