• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSpinner dateeditor issues

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?




Thanks.

Mark.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.setName("day");
day.setEditor(new JSpinner.DateEditor(day, "dd"));
day.addChangeListener(this);

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:


((JSpinner.DefaultEditor)day.getEditor()).getTextField().addKeyListener(this);
((JSpinner.DefaultEditor)day.getEditor()).getTextField().addFocusListener(this);

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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic