Skip to main content

How to Use The Swing JSpinner Class, by Kathy Walrath

8 replies [Last post]
jeff
Offline
Joined: 2003-06-10

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
davetron5000
Offline
Joined: 2003-06-10

> One useful trick with Spinners is to only process
> events after there have been no events for a few
> seconds. The reason for this is otherwise every click
> on the Spinner creates event handling. For example if
> you step through every second in a spinner
> representing seconds in a minute then you get an
> awful lot of event processing. I only process Spinner
> events when none have been generated for six seconds
> - which means the user has taken his or her paw off
> the keyboard...

Doesn't that violate some cardinal rule of usability? Like things should respond to clicks witing 200ms?

It's bad enough you subject the poor user to the tiny spinner buttons that complicate the simple task of entering a number on a keyboard, but then you ignore their clicks as well?

charles.armstrong
Offline
Joined: 2006-02-17

I think some developers are forgetting why Cardinal Rules exist ;) (adapted from your view in the other thread)..

I said delay the EVENT PROCESSING - you don't want to update a database 60 times for one change in the Datetime (because someone has clicked through the entire circle because they feel like it) ... Hence wait until they are done... If they do something like lose focus or change screen the update is instant...

Hope that is clearer...

davetron5000
Offline
Joined: 2003-06-10

Ah, I get it, and nice point regarding cardinal rules :)

That said, perhaps instead of delyaing event processing you shouldn't be using a spinner? I mean, I think the spinner is a debatable control anyway (don't most users want to avoid the mouse and use the keyboard?), but it seems like in your case, you either wouldn't want to use it, or you want to update the DB on an action event (e.g. button press) instead....

zander
Offline
Joined: 2003-06-13

> perhaps instead of delyaing event
> processing you shouldn't be using a spinner? I mean,
> I think the spinner is a debatable control anyway
> (don't most users want to avoid the mouse and use the
> keyboard?)

But that is exacly why you want to use a spinner; it provides both at the same time.

The user can choose which she likes best.

tinagao
Offline
Joined: 2006-02-17

Hi, I am happy to find many specialists here. I hope I could find some clues about my problem.

I have begun to use JSpinner recently. We support our product on both Windows and Mac OS. But it looks like that JSpinner with SpinnerDateModel and DateEditor does not work well when I try to set CalendarField with any mouse actions or key actions and then use up and down buttons to change the field.

Example: SpinnerDemo example provided along with "How to use ... " article

When using "Another Date" spinner, I can select the field (either month or year) I want to change by clicking the field with my mouse. In Windows, caret will then stay in this field, and when I click up or down button, the field will increment or decrement. However, under Mac, no matter which field I choose, the buttons can only change month field.

This problem also happens when using other kind of date format.

Any suggestions and helps are highly appreciated.

charles.armstrong
Offline
Joined: 2006-02-17

One useful trick with Spinners is to only process events after there have been no events for a few seconds. The reason for this is otherwise every click on the Spinner creates event handling. For example if you step through every second in a spinner representing seconds in a minute then you get an awful lot of event processing. I only process Spinner events when none have been generated for six seconds - which means the user has taken his or her paw off the keyboard...

zander
Offline
Joined: 2003-06-13

Qt does this even smarter; first they disable the pointer when the user starts to type and second when that pointer leaves the 'spinner' then the value is committed.

The latter is also done in the Spinner from the UICompiler open source project. Unfortunately this still generates too many events since I get a 'mouseleave' event when entering and when leaving, its these little bugs that make Swing always surprising to work with :)

zander
Offline
Joined: 2003-06-13

Note that the spinner has several serious bugs that limit its usablity in at least 1.4.2

See http://uic.sf.net/fixes
bug 38, 39, 40 and 41

Beside these the obvious omissions are things like a 'getValue()' - like method that returns an int without casting to an Integer, as well as supporting mousewheel action.

All of these are 'fixed' in UIC-themes and extending-classes. I just hope they will be standard in the next Java Release.

See for yourself at: http://uic.sourceforge.net/tutorials/configdiag.jnlp click on the color-button to get a color-config-dialog.