aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JSpinner dateeditor issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JSpinner dateeditor issues" Watch "JSpinner dateeditor issues" New topic
Author

JSpinner dateeditor issues

Mark Dary
Greenhorn

Joined: Jan 16, 2009
Posts: 29
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.
Kenneth McNeil
Greenhorn

Joined: Apr 23, 2010
Posts: 2
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

Joined: Apr 23, 2010
Posts: 2
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.

 
 
subject: JSpinner dateeditor issues