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.
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.
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.