Java JSpinner ajustarValorCambiador(JSpinner spnActual, int valor)

Here you can find the source of ajustarValorCambiador(JSpinner spnActual, int valor)

Description

ajustar Valor Cambiador

License

Apache License

Declaration

public static void ajustarValorCambiador(JSpinner spnActual, int valor) 

Method Source Code

//package com.java2s;
/* /*from www  .ja  v  a  2  s.  co  m*/
 * Copyright 2017 Jos? A. Pacheco Ondo?o - joanpaon@gmail.com.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.swing.JSpinner;

import javax.swing.event.ChangeListener;

public class Main {
    public static void ajustarValorCambiador(JSpinner spnActual, int valor) {
        // Captura los escuchadores del cambiador
        ChangeListener[] lista = spnActual.getChangeListeners();

        /**
         * Desactiva el primer ChangeListener para que no se propaguen eventos.
         * Si se desconectan todos los listeners el JSpinner no se actualiza con
         * el valor cambiado por set value.
         */
        spnActual.removeChangeListener(lista[0]);

        // Cambia el valor del spinner
        spnActual.setValue(valor);

        // Reconecta el primer ChangeListener
        spnActual.addChangeListener(lista[0]);
    }
}

Related

  1. adjustWithoutNotifyingListeners(JSpinner spinner, double value)
  2. createSpinner()
  3. createSpinner(SpinnerModel model)
  4. createSpinnerForm(String label, JSpinner spinner)
  5. dereferenceSpinnerNumberModel(SpinnerNumberModel model)