wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Editor with JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Editor with JDialog" Watch "Editor with JDialog" New topic
Author

Editor with JDialog

Giuseppa Cefalu
Ranch Hand

Joined: Jul 15, 2011
Posts: 121
Hi,

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.

Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 557
Where's your code for the JDialog?

You may also want to consider using a simple showMessageDialog to let the user know that they've made a mistake that needs fixing.


Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Giuseppa Cefalu
Ranch Hand

Joined: Jul 15, 2011
Posts: 121
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.

Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 557
Giuseppa
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,

?
Giuseppa Cefalu
Ranch Hand

Joined: Jul 15, 2011
Posts: 121
Is there an isValid function in java to test whether the date input formatter returns the valid or invalid value?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Giuseppa Cefalu
Ranch Hand

Joined: Jul 15, 2011
Posts: 121
Hellow there. Thank you for your help. Here is the code. It works fine now. let me know if you have any suggestions.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Editor with JDialog
 
Similar Threads
Still keeping my fingers crossed, Here's the code
updating date field
Hi guys !! I really need your help here ..
Date Editor
Null Value in JTable