How to limit JSpinner
此应用程序的有效范围是0到9,但似乎没有NetBeans 7.0.1 JSpinner的最小值或最大值设置。 还有另一种方法可以将此JSpinner的范围限制为0..9吗?
在我的Netbeans 7.3中,我遵循以下步骤:
步骤1:
第2步:
第三步:
最后一步4:
这对我行得通。
1 2 3 | // from 0 to 9, in 1.0 steps start value 5 SpinnerNumberModel model1 = new SpinnerNumberModel(5.0, 0.0, 9.0, 1.0); JSpinner spin1 = new JSpinner(model1); |
您必须使用
片段:
1 2 3 |
The valid range for this application is 0 to 9 but there seems to be
no NetBeans 7.0.1 JSpinner minimum or maximum value setting. Is there
another way to limit the range of this JSpinner to 0..9?
-
是的,但无需打扰插入代码和/或使用GUI Palette生成的代码
-
添加SpinnerListModel(最容易满足此要求和Oracle教程中的示例)或编写自己的SpinnerNumberModel