Java JSpinner adjustWithoutNotifyingListeners(JSpinner spinner, double value)

Here you can find the source of adjustWithoutNotifyingListeners(JSpinner spinner, double value)

Description

adjust Without Notifying Listeners

License

Open Source License

Declaration

public static void adjustWithoutNotifyingListeners(JSpinner spinner, double value) 

Method Source Code

//package com.java2s;
/*//  w ww.ja  v  a2 s  .  c  om
 *   Copyright (C) 2006  The Concord Consortium, Inc.,
 *   25 Love Lane, Concord, MA 01742
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * END LICENSE */

import javax.swing.JSlider;
import javax.swing.JSpinner;

import javax.swing.SpinnerNumberModel;

import javax.swing.event.ChangeListener;

public class Main {
    public static void adjustWithoutNotifyingListeners(JSlider slider, int value) {
        ChangeListener[] cl = slider.getChangeListeners();
        if (cl != null) {
            for (ChangeListener x : cl)
                slider.removeChangeListener(x);
        }
        slider.setValue(value);
        if (cl != null) {
            for (ChangeListener x : cl)
                slider.addChangeListener(x);
        }
    }

    public static void adjustWithoutNotifyingListeners(JSpinner spinner, double value) {
        ChangeListener[] cl = spinner.getChangeListeners();
        if (cl != null) {
            for (ChangeListener x : cl)
                spinner.removeChangeListener(x);
        }
        ((SpinnerNumberModel) spinner.getModel()).setValue(new Double(value));
        if (cl != null) {
            for (ChangeListener x : cl)
                spinner.addChangeListener(x);
        }
    }
}

Related

  1. ajustarValorCambiador(JSpinner spnActual, int valor)
  2. createSpinner()
  3. createSpinner(SpinnerModel model)
  4. createSpinnerForm(String label, JSpinner spinner)