JTable Custom Editors

I have a JTable and I want to add in two different forms of customization.

First, I want to validate that the String they enter into a date column is a valid date and not allow them to stop editing until they either enter a valid date or hit a key to clear the field and move on without putting anything in it.

Second, on some fields I know the exact length of the field. For example, for a column named "Type of Service" it will always be two digits. So I need to two things, one ties in with the first and it is validate that they entered two digits, the second is as soon as they enter in the second digit I want to move to the next field.

Not sure how to make this work with a custom editor. The validation shouldn't be too difficult, but how do I go about moving to the next field when they hit the second digit?

[843 byte] By [kablaira] at [2007-10-2 1:59:09]
# 1

> First, I want to validate that the String they enter...

Here's an example of a custom editor. You would need to modify it to do the date validation.

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=645740

> Second, on some fields I know the exact length of the field...

Almost the code as given in the example above with a couple of changes:

a) add a DocumentListener to the JTextField being used as the editor. Then when an insert occurs you would check the length of the Document and invoke the stopCellEditing() method of the editor.

b) In the stopCellEditing() method you would need to add additional code to startEditing on the next cell.

camickra at 2007-7-15 19:40:24 > top of Java-index,Desktop,Core GUI APIs...
# 2
Just what I needed to know, thanks.
kablaira at 2007-7-15 19:40:24 > top of Java-index,Desktop,Core GUI APIs...