Listening for a Property Change Event - Java Swing

Java examples for Swing:Event

Description

Listening for a Property Change Event

Demo Code


import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JButton;

public class Main {
  public void m() {
    // Register for property change events on the bean
    JButton bean = new JButton();
    bean.addPropertyChangeListener(new MyPropertyChangeListener());
  }/*  w ww . ja  v a 2 s  .  com*/
  class MyPropertyChangeListener implements PropertyChangeListener {
    public void propertyChange(PropertyChangeEvent evt) {
      // Get the old value of the property
      Object oldValue = evt.getOldValue();

      // Get the new value of the property
      Object newValue = evt.getNewValue();
    }
  }
}

Related Tutorials