Here you can find the source of createDoubleSpinner(final double value, final double rangeMinimum, final double rangeMaximum, final double stepSize, final double bigStepSize, final String formatPattern)
public static JSpinner createDoubleSpinner(final double value, final double rangeMinimum, final double rangeMaximum, final double stepSize, final double bigStepSize, final String formatPattern)
//package com.java2s; /*/*from ww w . j av a2 s . co m*/ * Copyright (C) 2010 Brockmann Consult GmbH (info@brockmann-consult.de) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) * any later version. * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, see http://www.gnu.org/licenses/ */ import javax.swing.AbstractAction; import javax.swing.ActionMap; import javax.swing.InputMap; import javax.swing.JComponent; import javax.swing.JSpinner; import javax.swing.KeyStroke; import javax.swing.SpinnerNumberModel; import java.awt.event.ActionEvent; import java.text.DecimalFormat; public class Main { public static JSpinner createDoubleSpinner(final double value, final double rangeMinimum, final double rangeMaximum, final double stepSize, final double bigStepSize, final String formatPattern) { final SpinnerNumberModel numberModel = new SpinnerNumberModel(value, rangeMinimum, rangeMaximum, stepSize); final JSpinner spinner = new JSpinner(numberModel); final JComponent editor = spinner.getEditor(); if (editor instanceof JSpinner.NumberEditor) { JSpinner.NumberEditor numberEditor = (JSpinner.NumberEditor) editor; final DecimalFormat format = numberEditor.getFormat(); format.applyPattern(formatPattern); numberEditor.getTextField().setColumns(8); } final Double sss = stepSize; final Double bss = bigStepSize; final String bigDec = "dec++"; final String bigInc = "inc++"; final InputMap inputMap = spinner.getInputMap(); final ActionMap actionMap = spinner.getActionMap(); // big increase with "PAGE_UP" key inputMap.put(KeyStroke.getKeyStroke("PAGE_UP"), bigInc); actionMap.put(bigInc, new AbstractAction() { public void actionPerformed(ActionEvent e) { numberModel.setStepSize(bss); numberModel.setValue(numberModel.getNextValue()); numberModel.setStepSize(sss); } }); // big decrease with "PAGE_UP" key inputMap.put(KeyStroke.getKeyStroke("PAGE_DOWN"), bigDec); actionMap.put(bigDec, new AbstractAction() { public void actionPerformed(ActionEvent e) { numberModel.setStepSize(bss); numberModel.setValue(numberModel.getPreviousValue()); numberModel.setStepSize(sss); } }); return spinner; } }