Java JSpinner setSpinnerFloatValue(JSpinner sp, float f)

Here you can find the source of setSpinnerFloatValue(JSpinner sp, float f)

Description

Utility function to write to the spinner value.

License

BSD License

Parameter

Parameter Description
sp - spinning that should be set
f - new value for the spinner

Declaration

public static void setSpinnerFloatValue(JSpinner sp, float f) 

Method Source Code

//package com.java2s;
// LICENSE:      This file is distributed under the BSD license.

import javax.swing.JSpinner;

public class Main {
    /**//  w  ww .  j a  va  2s . c  om
     * Utility function to write to the spinner value.
     * @param sp - spinning that should be set
     * @param f - new value for the spinner
     */
    public static void setSpinnerFloatValue(JSpinner sp, float f) {
        // TODO figure out why the type of value in the numbermodel is 
        // changing type to float which necessitates this code
        // this should call change listener
        try {
            sp.setValue((Double) ((double) f));
        } catch (Exception ex) {
            sp.setValue((Float) f);
        }
    }

    /**
     * Utility function to write to the spinner value.
     * @param sp spinner whole value should be set
     * @param d new value for the spinner
     */
    public static void setSpinnerFloatValue(JSpinner sp, double d) {
        // TODO figure out why the type of value in the numbermodel is 
        // changing type to float which necessitates this code
        try {
            sp.setValue((Double) d);
        } catch (Exception ex) {
            sp.setValue((Float) ((float) d));
        }
    }
}

Related

  1. installSpinnerBugWorkaround(final JSpinner spinner)
  2. reattachChangeListeners(JSpinner spinner, ChangeListener[] listeners)
  3. replaceSpinnerValue(JSpinner spinner, double value)
  4. setList(JSpinner spinner, List values)
  5. setRightAlignment(JSpinner spinner)
  6. setSpinnerValue(JSpinner spinner, Integer i)