Java Swing Tutorial - Java JSpinner.getChangeListeners()








Syntax

JSpinner.getChangeListeners() has the following syntax.

public ChangeListener [] getChangeListeners()

Example

In the following code shows how to use JSpinner.getChangeListeners() method.

import java.awt.BorderLayout;
//from w w  w .  j av  a  2  s  . c  o  m
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class Main {

  public static void main(final String args[]) {
    JFrame frame = new JFrame("JSpinner Dates");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ChangeListener listener = new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        System.out.println("Source: " + e.getSource());
      }
    };

    SpinnerModel model3 = new SpinnerNumberModel();
    JSpinner spinner3 = new JSpinner(model3);
    spinner3.addChangeListener(listener);

    ChangeListener[] changeListeners = spinner3.getChangeListeners();
    
    frame.add(spinner3, BorderLayout.SOUTH);

    frame.setSize(200, 90);
    frame.setVisible(true);

  }

}