Here you can find the source of replaceSpinnerValue(JSpinner spinner, double value)
public static void replaceSpinnerValue(JSpinner spinner, double value)
//package com.java2s; // LICENSE: This file is distributed under the BSD license. import javax.swing.*; import javax.swing.event.ChangeListener; import javax.swing.text.JTextComponent; public class Main { public static void replaceSpinnerValue(JSpinner spinner, double value) { ChangeListener[] listeners = detachChangeListeners(spinner); spinner.setValue(value);/* w ww . j a v a 2 s . co m*/ reattachChangeListeners(spinner, listeners); } public static ChangeListener[] detachChangeListeners(JSpinner spinner) { ChangeListener[] listeners = spinner.getChangeListeners(); for (ChangeListener listener : listeners) { spinner.removeChangeListener(listener); } return listeners; } public static void setValue(JComponent component, String value) { if (component instanceof JTextComponent) { ((JTextComponent) component).setText(value); } if (component instanceof JComboBox) { ((JComboBox) component).setSelectedItem(value); } if (component instanceof JList) { ((JList) component).setSelectedValue(value, true); } } public static void setValue(JComponent component, Object value) { String valueText = value.toString(); if (component instanceof JTextComponent) { ((JTextComponent) component).setText(valueText); } if (component instanceof JComboBox) { ((JComboBox) component).setSelectedItem(valueText); } if (component instanceof JList) { ((JList) component).setSelectedValue(valueText, true); } } public static void reattachChangeListeners(JSpinner spinner, ChangeListener[] listeners) { for (ChangeListener listener : listeners) { spinner.addChangeListener(listener); } } }