33

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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
jacknad
  • 13,483
  • 40
  • 124
  • 194
  • 2
    See [`SpinnerNumberModel`](http://docs.oracle.com/javase/7/docs/api/javax/swing/SpinnerNumberModel.html) which allows to specify min/max values in the constructor – Robin Apr 08 '13 at 13:54

4 Answers4

64

In my Netbeans 7.3 i followed theese steps:

Step 1:

swing spinner spinnernumbermodel

Step 2:

swing spinner spinnernumbermodel

Step 3:

swing spinner spinnernumbermodel

And final step 4:

enter image description here

That works for me.

Oguz Ozkeroglu
  • 3,025
  • 3
  • 38
  • 64
22
// 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);
Tator
  • 566
  • 6
  • 21
15

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);
Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108
2

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?

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319