Java Utililty Methods JSpinner

List of utility methods to do JSpinner

Description

The list of methods to do JSpinner are organized into topic(s).

Method

floatgetFloat(JSpinner spinner)
get Float
float rv = 0;
Object o = spinner.getValue();
if (o != null) {
    if (o instanceof Number) {
        rv = ((Number) o).floatValue();
return rv;
...
intgetInt(JSpinner spinner)
get Int
int rv = 0;
Object o = spinner.getValue();
if (o != null) {
    if (o instanceof Number) {
        rv = ((Number) o).intValue();
return rv;
...
intgetInt(SpinnerNumberModel model)
get Int
return (int) model.getValue();
JSpinnergetOnlySpinner(Container owner)
get Only Spinner
return (JSpinner) getOnlyComponent(owner, JSpinner.class);
floatgetSpinnerFloatValue(JSpinner sp)
Utility function to access the spinner value.
float f;
try {
    f = (float) ((Double) sp.getValue()).doubleValue();
} catch (Exception ex) {
    f = ((Float) sp.getValue()).floatValue();
return f;
DefaultFormattergetSpinnerFormatter(JSpinner spinner)
get Spinner Formatter
JComponent comp = spinner.getEditor();
JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
return (DefaultFormatter) field.getFormatter();
intgetSpinnerInt(JSpinner aSpinner)
Gets the currently selected integer value in a spinner control.
return ((SpinnerNumberModel) aSpinner.getModel()).getNumber().intValue();
intgetSpinnerIntValue(final JSpinner spinner)
get Spinner Int Value
if (spinner == null || spinner.getModel() == null) {
    return 1;
int value = Integer.valueOf(spinner.getModel().getValue().toString());
try {
    value = NumberFormat.getIntegerInstance()
            .parse(((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getText()).intValue();
} catch (NumberFormatException e) {
...
intgetSpinnerIntValue(JSpinner spin)
Evaluates the numeric int value of a spinner object
return getSpinnerDoubleValue(spin).intValue();
voidinstallSpinnerBugWorkaround(final JSpinner spinner)
Installs a workaround for bug #4699955 in a JSpinner.
((DefaultEditor) spinner.getEditor()).getTextField().addFocusListener(new FocusAdapter() {
    @Override
    public void focusGained(final FocusEvent e) {
        if (e.getSource() instanceof JTextComponent) {
            final JTextComponent text = ((JTextComponent) e.getSource());
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
...