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

voidreattachChangeListeners(JSpinner spinner, ChangeListener[] listeners)
reattach Change Listeners
for (ChangeListener listener : listeners) {
    spinner.addChangeListener(listener);
voidreplaceSpinnerValue(JSpinner spinner, double value)
replace Spinner Value
ChangeListener[] listeners = detachChangeListeners(spinner);
spinner.setValue(value);
reattachChangeListeners(spinner, listeners);
voidsetList(JSpinner spinner, List values)
Assign the List model (for a list-based spinner)
SpinnerModel model = spinner.getModel();
if (model instanceof SpinnerListModel) {
    ((SpinnerListModel) model).setList(values);
} else {
    throw new IllegalArgumentException("Spinner model is not a SpinnerListModel");
voidsetRightAlignment(JSpinner spinner)
Align the spinner display to the right
JSpinner.DefaultEditor editor;
editor = (JSpinner.DefaultEditor) spinner.getEditor();
editor.getTextField().setHorizontalAlignment(JTextField.RIGHT);
voidsetSpinnerFloatValue(JSpinner sp, float f)
Utility function to write to the spinner value.
try {
    sp.setValue((Double) ((double) f));
} catch (Exception ex) {
    sp.setValue((Float) f);
voidsetSpinnerValue(JSpinner spinner, Integer i)
set Spinner Value
if (i == null) {
    spinner.setValue(-1);
} else {
    spinner.setValue(i);