I have an editor that works very well. It forces the user to input date with format "yyyy-MM-dd". Also my table displays the date formated as "yyyy-MM-dd". If the user inputs the wrong date or the wrong format, the input gets deleted and replaced by the current date (new Date()). The problem that I see with this editor is that the user may not realize that his/her incorrect input is being replaced with the current date and he/she may not reenter the correct date (one error gets replaced with another). I am trying to create a JDialog that warns the user about the wrong input; but I cannot make it work in the wright way. Could any one help to get started in the right direction? below is the code so far. I have tried to replace the wrong input with 0000-00-00; put it is not possible becuase new Date() will not accept a string.
You may also want to consider using a simple showMessageDialog to let the user know that they've made a mistake that needs fixing.
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Joined: Jul 15, 2011
Thank you! Capturing a letter to return a dialog message is not a problem. the problem is how to capture the wrong or malformatted date in order to issue the dialog. This is my approach so far -I have added a dialog to the Document class.
Joined: Oct 24, 2010
the problem is how to capture the wrong or malformatted date in order to issue the dialog.
You would capture the data by getting the text from the JTextField or DateField.
By the way, it's odd to create a class extending a minor component like a JTextField. Why not just create the component within your class,
Joined: Jul 15, 2011
Is there an isValid function in java to test whether the date input formatter returns the valid or invalid value?
DateFormat has method parse(String, ParsePosition) that returns null if the String is not a valid date. That still allows other "garbage" text after the valid date, which you can get rid off by checking the ParsePosition's index with the String length - if they are not equal after parsing there is "garbage" text.