• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

JSpinner dateeditor issues  RSS feed

Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have several issues with spinners and date editors.

The main objectives I have are:

a spinner for hours and minutes
set foreground color (eg green) while editing
set foreground color (eg black) when finished
do not allow invalid edits OR set foreground color (eg red) if invalid

My first issue is that when I enter a number manually (eg 1) without the spinner controls, the hours jump 4 at a time.

The second main issue is how to set the foreground color while editing.

I have the following stipped down version, but don't know how to take it further, can anyone help?


Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having the same issue. Does anybody know the answer?

SpinnerDateModel daymodel = new SpinnerDateModel(initDate, earliestDate,latestDate, Calendar.YEAR);
JSpinner day = new JSpinner(daymodel);
day.setEditor(new JSpinner.DateEditor(day, "dd"));

I implement the stateChanged(ChangeEvent e)

But what do I put in it?

public void stateChanged(ChangeEvent e) {


Tried all sorts of things such as:

SpinnerModel dateModel = day.getModel();
day.setValue( dateModel.getValue());

Trying to make the model update fire so that when I click on a button (out side of the JPanel containing the JSpinner

It will get the updated model.

I tried mouse listeners, focus listeners, key listeners and all their association methods. They all fire but still the model will not update. Only changing the text then
pressing ENTER will the modle update fire. Spin controls work like a champ.

I did these too:


Trying to put the listener events on the TextField in the JSpinner.

Out of frustration I disabled manual text entry and forcing the user to spin the spinner or use the up and down arrow key to change the values which do fire the
events and update the model.

Any help would be appreciated.

Kenneth McNeil
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out the fix to updating the model.

call the spinner.commitEdit() method at the appropriate place. I found that the stateChanged method is not always called.
So where the event is called to get the information out of the spinner model I called it there right before getting the data.

Hope this helps someone.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!