Forums Register Login

JSpinner dateeditor issues

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.








+Pie Number of slices to send: Send
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.

My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2723 times.
Similar Threads
How to insert date values to database using java swings
JSpinner Problem
jspinner background color
JSpinner decimal input
How to checked CheckBox in JTree only when user click on CheckBox?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:55:50.