Example usage for javax.swing SpinnerNumberModel addChangeListener

List of usage examples for javax.swing SpinnerNumberModel addChangeListener

Introduction

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

Prototype

public void addChangeListener(ChangeListener l) 

Source Link

Document

Adds a ChangeListener to the model's listener list.

Usage

From source file:Main.java

public Main() {
    MyCanvas thingy = new MyCanvas();
    setLayout(new BorderLayout());
    JPanel panel = new JPanel();
    panel.add(thingy);/*from ww  w .j a  v a  2s  .co  m*/
    JScrollPane scroll = new JScrollPane();
    scroll.setViewportView(panel);
    add(scroll, BorderLayout.CENTER);
    SpinnerNumberModel spmodel = new SpinnerNumberModel(thingy.getThingySize(), 10.0, 2000.0, 10.0);
    spmodel.addChangeListener(e -> thingy.setThingySize((Double) spmodel.getNumber()));
    add(new JSpinner(spmodel), BorderLayout.NORTH);
}