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

voidadjustWithoutNotifyingListeners(JSpinner spinner, double value)
adjust Without Notifying Listeners
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)
...
voidajustarValorCambiador(JSpinner spnActual, int valor)
ajustar Valor Cambiador
ChangeListener[] lista = spnActual.getChangeListeners();
spnActual.removeChangeListener(lista[0]);
spnActual.setValue(valor);
spnActual.addChangeListener(lista[0]);
JSpinnercreateSpinner()
create Spinner
return new JSpinner();
JSpinnercreateSpinner(SpinnerModel model)
create Spinner
JSpinner result = new JSpinner(model);
return result;
BoxcreateSpinnerForm(String label, JSpinner spinner)
create Spinner Form
Box panel = Box.createHorizontalBox();
panel.add(Box.createHorizontalGlue());
panel.add(new JLabel(label));
panel.add(Box.createHorizontalGlue());
panel.add(spinner);
return panel;
voiddereferenceSpinnerNumberModel(SpinnerNumberModel model)
dereference Spinner Number Model
for (ChangeListener listener : model.getChangeListeners()) {
    model.removeChangeListener(listener);
ChangeListener[]detachChangeListeners(JSpinner spinner)
detach Change Listeners
ChangeListener[] listeners = spinner.getChangeListeners();
for (ChangeListener listener : listeners) {
    spinner.removeChangeListener(listener);
return listeners;
voidfixIntegerList(final JSpinner spinner)
Workaround for a swing bug : when the user enters an illegal value, the text is forced to the last value.
JSpinner.DefaultEditor editor;
editor = (JSpinner.DefaultEditor) spinner.getEditor();
final JFormattedTextField ftf = editor.getTextField();
ftf.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enterAction");
ftf.getActionMap().put("enterAction", new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
        try {
...
voidformatSpinner(JSpinner spinner, String format)
format Spinner
JComponent editor = spinner.getEditor();
Dimension preferredSize = null;
if (editor instanceof JSpinner.NumberEditor) {
    JSpinner.NumberEditor numberEditor = (JSpinner.NumberEditor) editor;
    numberEditor.getFormat().applyPattern(format);
    preferredSize = calculateDimensionForFormat(format);
} else if (editor instanceof JSpinner.DateEditor) {
    JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
...
JSpinnergenerateSpinnerFor(Object... objs)
generate Spinner For
Container c = search(objs, Container.class);
String[] name_value = search(objs, String[].class);
ChangeListener listener = search(objs, ChangeListener.class);
SpinnerModel model = search(objs, SpinnerModel.class);
Color color = search(objs, Color.class);
Dimension dimension = search(objs, Dimension.class);
Font font = search(objs, Font.class);
Rectangle bounds = search(objs, Rectangle.class);
...