Example usage for javax.swing SpinnerModel addChangeListener

List of usage examples for javax.swing SpinnerModel addChangeListener

Introduction

In this page you can find the example usage for javax.swing SpinnerModel addChangeListener.

Prototype

void addChangeListener(ChangeListener l);

Source Link

Document

Adds a ChangeListener to the model's listener list.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    JFrame frame = new JFrame();

    Calendar now = Calendar.getInstance();
    Calendar earliest = (Calendar) now.clone();
    earliest.add(Calendar.MONTH, -6);
    Calendar latest = (Calendar) now.clone();
    latest.add(Calendar.MONTH, 6);
    SpinnerModel model = new SpinnerDateModel(now.getTime(), earliest.getTime(), latest.getTime(),
            Calendar.WEEK_OF_YEAR);
    final JSpinner spinner = new JSpinner(model);

    model.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            System.out.println(((SpinnerDateModel) e.getSource()).getDate());
        }/*ww w.j  a va  2 s.c  o m*/
    });

    frame.getContentPane().add("North", new JLabel("Choose a week"));
    frame.getContentPane().add("Center", spinner);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:com.anrisoftware.prefdialog.fields.spinner.SpinnerField.java

/**
 * Sets the spinner model for the field.
 * //www.  j  a v  a 2 s.  co m
 * @param model
 *            the {@link SpinnerModel}.
 * 
 * @throws NullPointerException
 *             if the specified model is {@code null}.
 */
public void setModel(SpinnerModel model) {
    log.checkModel(this, model);
    removeOldModel();
    getComponent().setModel(model);
    model.addChangeListener(changeListener);
    customModelSet = true;
    log.modelSet(this, model);
}