Note that there are some explanatory texts on larger screens.

plurals
  1. POPropertyChangeSupport for SpinnerNumberModel
    text
    copied!<p>I want to listen to the changes of the value of the SpinnerNumberModel for a JSpinner.<br> I create a PropertyChangeSupport and put the model into it.</p> <p>I need the propertyChangeListener, because it shows me the old and new value of the property. </p> <p>The snippet doesn't work: the <code>propertyChange</code> method prints nothing, when I click on the JSpinner.<br> A simple ChangeListener give only the new value, but I need also the old value, how can I get it?</p> <pre><code>package de.unikassel.jung; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import javax.swing.JFrame; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; public class PropertyChangeTest implements PropertyChangeListener { public static void main(String[] args) { new PropertyChangeTest(); } public PropertyChangeTest() { JFrame frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int value = 1; int min = 0; int max = 10; int step = 1; SpinnerNumberModel spinnerModel = new SpinnerNumberModel(value, min, max, step); PropertyChangeSupport pcs = new PropertyChangeSupport(spinnerModel); pcs.addPropertyChangeListener("value", this); JSpinner spinner = new JSpinner(spinnerModel); frame.getContentPane().add(spinner); frame.setVisible(true); } @Override public void propertyChange(PropertyChangeEvent evt) { System.out.println(evt); System.out.println(evt.getSource()); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload