JSpinner without negative values

女生的网名这么多〃 提交于 2019-12-06 05:33:24

for JSpinner you have to implements SpinnerNumberModel

import javax.swing.*;

public class SpinnerModelTest {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                new SpinnerModelTest().makeUI();
            }
        });
    }

    public void makeUI() {
        SpinnerModel modeltau = new SpinnerNumberModel(0.0002, 0.0001, 100.0000, 0.0001);
        JSpinner spinner = new JSpinner(modeltau);
        ((JSpinner.NumberEditor) spinner.getEditor()).getFormat().setMaximumFractionDigits(4);
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(spinner);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
BullyWiiPlaza

It works with r0ast3d's library reference:

((SpinnerNumberModel) mySpinner.getModel()).setMinimum(0);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!