Results 1 to 5 of 5
Thread: SpinnerDateModel questions
- 04-30-2010, 09:05 PM #1
Member
- Join Date
- Mar 2010
- Location
- Belgrade, Serbia
- Posts
- 27
- Rep Power
- 0
SpinnerDateModel questions
In my application user needs to input date. I read the Java API and found that I can solve this with the following code
Java Code:dataReceivedDateSpinner = new JSpinner(new SpinnerDateModel());
I have two problems.
First: dataReceivedDateSpinner displays year, month, day, hour and minutes. And it is displaying it as far as I can tell according to system time settings. On my home computer which runs Linux format is 4/30/10 9:10 PM. At work where we use Serbian Windows settings format is petak 30.4.2010 21:10. Is there a way for me to set the format to let say DD/MM/YYYY. I would like system independent formating. Plus I don't need the time just the date. Is there a way to at least turn the time off and is there a way to tell the JSpinner or SpinnerDateModel in which format I want data to be displayed.
Second: I can get the Date from dataReceivedDateSpinner and set value in the following fashion
Java Code:Date date = (Date) dataReceivedDateSpinner.getModel().getValue(); dataReceivedDateSpinner.getModel().setValue(date);
Problem is that, as far as I understood Java api, most methods of Date class are deprecated. Recommendation is not to use them. I have fields in my classes that I want to use for dates and those fields are instances of GregorianCalendar. I googled extensively but found no way to switch back and forth betwen GregorianCalendar class and Date class.
Is there a way to use some up to date class to store date information and convert data from Date class to that up to date class and back or do I have to use deprecated methods of the Date class. I would really like to avoid using Date class methods because they are deprecated.
Thanks in advance
-
For your first problem, I think that you can solve it by giving your JSpinner a custom JSpinner.DateEditor editor. Please check out the API here: JSpinner.DateEditor (Java Platform SE 6)
There's a constructor that takes a JSpinner and Date format pattern String as parameters which will likely solve your problem. Then use JSpinner's setEditor method to set the editor with your object.
- 05-01-2010, 08:25 AM #3
Member
- Join Date
- Mar 2010
- Location
- Belgrade, Serbia
- Posts
- 27
- Rep Power
- 0
Thank you. I solved first problem with
Java Code:dataReceivedDateSpinner = new JSpinner(new SpinnerDateModel()); dataReceivedDateSpinner.setEditor(new JSpinner.DateEditor(dataReceivedDateSpinner, TypeDefinitions.DATE_FORMAT));
Where TypeDefinitions.DATE_FORMAT is "dd.MM.yyyy". I set editors to all JSpinners that are used for date input like this.
Does anybody know any solution for my second problem? Is working with Date class all the way the only way to get and set value to JSpinner created in the above fashion.
- 05-01-2010, 08:53 AM #4
- 05-01-2010, 09:13 AM #5
Member
- Join Date
- Mar 2010
- Location
- Belgrade, Serbia
- Posts
- 27
- Rep Power
- 0
I don't know how to thank you enough. I must have read GregorianCalendar API 15 times. It was very strange to me that there were no methods that will enable GregorianCalendar Class to work with Date class expecially considering Date class was deprecated . Somehow I managed to miss those methods.
Thank you.
Similar Threads
-
Some Questions
By MuslimCoder in forum New To JavaReplies: 2Last Post: 02-25-2009, 04:01 PM -
questions for 1yr exp
By rahaman.athiq in forum Java ServletReplies: 2Last Post: 11-26-2008, 01:13 AM -
Questions About JSP?
By mtz1406 in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 08-19-2008, 07:56 PM -
questions
By Gilgamesh in forum New To JavaReplies: 3Last Post: 11-27-2007, 11:18 PM -
3 Questions
By hiranya in forum AWT / SwingReplies: 4Last Post: 11-14-2007, 04:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks