0

I would not have throught this would be such a big problem, but im trying to get the value from a jSpinner called spinHours that is using the default SpinnerNumberModel.

spinHours.getValue().toString();

The above always returns 0. I need is as a string for later, but i've also tried:

SpinnerNumberModel model = (SpinnerNumberModel)spinHours.getModel();
int value = model.getNumber().intValue();

Where the value integer is 0 too.

Am i missing something really obvious?

When my jFrame loads i use the following line in the constructor to set the model for the jSpinner:

spinHours.setModel(new SpinnerNumberModel(0,0,99,1));
Daniel Jørgensen
  • 1,183
  • 2
  • 19
  • 42

1 Answers1

1
try

time = (Date)spinHours.getValue();
String formattedDate = format.format(time);

or 

jSp = spinHours.setModel(new SpinnerNumberModel(0,0,99,1));
Integer value = (Integer)jSp.getValue();

useful links:

how can I get the value of a the selected item in a JSpinner?

Getting the value from JSpinner (SWING)

Community
  • 1
  • 1
websky
  • 3,047
  • 1
  • 33
  • 31