|
| |||||||||
| Tags: components, date, format, graphical user interface, jtextfield, swing |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Get Date by JTextField
Hello, I would like via a form JTextField ask the user a date and format for format MM-dd-yyyy HH: mm. If you are suggesting me the SimpleDateFormat then I can not use it, I would like the user to enter Quote:
I need to verify that the date is. Can any one help me with this. Thanks in advance. |
|
#2
| |||
| |||
| Re: Get Date by JTextField
Hello, I have tried this before but was unsuccessful, if you need the code what I tried then it is here Code: static Public String ToDate(String dt)
{
DateFormat dtfrm = new SimpleDateFormat("MM-dd-yyyy HH: mm");
try {
dt = dtfrm.format(dt);
} catch (RuntimeException e) {
e.printStackTrace();
}
return dt;
} |
|
#3
| |||
| |||
| Re: Get Date by JTextField
Hello, This is normal, it should pass a "dt" Code: dtfrm.format(...) Code: SimpleDateFormat dtfrm1 = new SimpleDateFormat ("MM-dd-yyyy"); |
|
#4
| |||
| |||
| Re: Get Date by JTextField
Hello, You take your string you pass to the method parse your SimpleDateFormat. This method throws a ParseException if the string does not match the expected format and if the string is not a valid date. The parse method returns an object you date that you can use in a format thereafter. If you need any help regarding this topic then you can post back and we will try to solve it. |
|
#5
| |||
| |||
| Re: Get Date by JTextField
Hello, You can make a JFormattedTextField to date: Code: DateFormat dtfrm = new SimpleDateFormat("MM-dd-yyyy");
chdt = new JFormattedTextField(dtfrm); |
|
#6
| |||
| |||
| Re: Get Date by JTextField
Hello, For the first point, to pass a date format (). OK but why autocompletion offers me a format that parameter for a string? if the class was not overloaded with a String parameter I will not be able to compile. For the second point Code: SimpleDateFormat dtfrm1 = new SimpleDateFormat ( "MM-dd-yyyy"); |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Get Date by JTextField" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Custom Background Icon for JTextField? | melston | Software Development | 3 | 22-08-2010 01:02 PM |
| Display JtextField in Jpanel | New ID | Software Development | 5 | 04-03-2010 12:01 PM |
| How to write a wrapper around the JTextField class? | MAHAH | Software Development | 4 | 12-02-2010 07:01 PM |
| [JAVA] query results in a combobox and jtextfield | Aamin | Software Development | 5 | 31-03-2009 03:20 PM |
| How Can i achieve the functionality of TextListener for JTextField | Gap meer | Software Development | 4 | 25-10-2008 07:08 PM |