Re: JSlider and JSpinner
Rita Erfurt wrote:
Hi,
Can somebody help me to eliminate the error in the connection of JSlider
with JSpinner please?
Changes from slider to spinner work. Changes from spninner to slider don't
work, if I use the arrow keys.
ChangeListener listener = new ChangeListener() {
public void stateChanged(ChangeEvent e) {
JSlider s = (JSlider) e.getSource();
spinner.setValue(s.getValue());
System.out.println("slider " + s.getValue());
}
};
slider.addChangeListener(listener);
ChangeListener spinnerlistener = new ChangeListener() {
public void stateChanged(ChangeEvent e) {
JSpinner s = (JSpinner) e.getSource();
Object value = s.getValue();
int v = ((Integer) (value)).intValue();
slider.setValue(v);
System.out.println("spinner " + v);
}
};
spinner.addChangeListener(spinnerlistener);
Viele Gr??e
Rita
I was going to suggest you instead consider creating a class:
public class BoundedRangeSpinnerModel implements BoundedRangeModel,
SpinnerModel {
// details left as an exercise for the reader
}
however, they have conflicting methods (Object getValue() vs int getValue())
However, I would still consider creating your own Model implementations
that is backed by the same data, rather than adding listeners to both
components.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>