0

Right now I have a jFrame Spinner that just has numbers. I am storing the value of the spinner like this

    int value = (Integer) jSpinner1.getValue();

And am then outputting it to a jLabel like this

    jLabel5.setText("Counter = " + value );

I was wondering if there is a way to update the jLabel every time the number is changed on the spinner?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Jonah
  • 1,013
  • 15
  • 25

1 Answers1

3

Add a ChangeListener and set your label there.

JLabel l = ...;
JSpinner spinner = ...;
spinner.addChangeListener(new ChangeListener() {
  public void stateChanged(ChangeEvent e) {
    l.setText("Counter = " + spinner.getValue());
  }
}
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80