• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSpinner Value Format  RSS feed

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to implement a JSpinner for getting a time value. After looking at examples, I came up with the following:

That gives me exactly what I want. My problem is that I cannot understand from the examples, how to set or get values. That is, I know about getValue and setValue but I don't know what to pass them. For example, in my code above I want to initialize the spinner to 0:00. How do I do that? TIA.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another one of those over-generalized APIs. (When the API designers find themselves having to pass an Object, you know there's a design problem.)

Anyway the documentation for the setValue(Object) mention fairly clearly says that you have to pass a Date object. It is a "Date" spinner after all, so that shouldn't be that surprising.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. That is the part that is giving me trouble. I don't have a date, just a time. I don't care about the date but the object wants date information. Perhaps I am misusing JSpinner?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a JTimeSpinner?

If not, then you might have to use a JDateSpinner and bend it to your will. My guess would be to pass it a Date with the time portion set to a suitable value.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently not. As far as I can tell, every time spinner example, uses something similar but never discusses setting or getting values. Since the user theoretically never sees any date info, I guess I can set the date to anything in order to initialize the time on setValue and just ignore any date info on getValue.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I guess the default value is "now", which makes all of those examples do something which appears to be useful. Anyway, give that a try and let us know how it goes.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This field is being used for a length in hours and minutes so the date is irrelevant and the length will never exceed a few hours. It seems like this spinner is the easiest way to implement it. However, all the methods I need to use for the Date object are depreciated with no replacement as far as I can see.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a Calendar object and then get the Date out of that.

Or use a String and then a SimpleDateFormat to parse it into a Date.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I am moving forward but have one little issue. This is what I added:

The problem is that this uses a 12 hour format (1-12) and I need 24 hour format (0-23).
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do either 12-hour or 24-hour format with SimpleDateFormat, just read the docs a little more.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are referring to using H rather than h, it doesn't seem to matter. However, I'll keep reading.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that was what I was referring to (without having checked the docs). But is your problem that the parser doesn't handle "13:59" correctly or that the spinner doesn't display it correctly?
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I figured it out. It is the model that needs the H not necessarily the editor.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!