How to limit JSpinner

╄→尐↘猪︶ㄣ 提交于 2019-11-29 02:27:25

问题


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?


回答1:


In my Netbeans 7.3 i followed theese steps:

Step 1:

Step 2:

Step 3:

And final step 4:

That works for me.




回答2:


// 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);



回答3:


You'll have to use this constructor of SpinnerNumberModel.

Snippet:

JFrame frame = new JFrame("Limiting value for a JSpinner");
  SpinnerModel sm = new SpinnerNumberModel(0, 0, 9, 1); //default value,lower bound,upper bound,increment by
  JSpinner spinner = new JSpinner(sm);



回答4:


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?

  • yes but without bothering insert code and/or with generated code from GUI Palette

  • add SpinnerListModel (easiest for this requirement and example in Oracle tutorial) or wrote own SpinnerNumberModel



来源:https://stackoverflow.com/questions/15880844/how-to-limit-jspinner

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