Java JSlider adjustWithoutNotifyingListeners(JSlider slider, int value)

Here you can find the source of adjustWithoutNotifyingListeners(JSlider slider, int value)

Description

adjust Without Notifying Listeners

License

Open Source License

Declaration

public static void adjustWithoutNotifyingListeners(JSlider slider, int value) 

Method Source Code

//package com.java2s;
/*// w ww  . j  a  v a2s.  c  o m
 *   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. addVerticalMouseListener(final JPanel panel, final JSlider slider)
  2. ajustarValorDeslizador(JSlider sldActual, int valor)
  3. buildIntegerFieldWithSlider(final JSlider matchingSlider)
  4. createJSlider(final BoundedRangeModel model)
  5. createLabelField(String preText, String postText, JSlider s)