chrisjmurphy - 2007-10-22

Instead of using a DateFormatter, a simple fix can be made so that nulls can be commitEdit()ed to the JFormattedTextField. This code snippet is from MDateField:

    public MDateField(DateFormat df)
    {
        super(new NullCapableDateFormatter(df));
        init();
    }
   
    /**
     * To do this enhancement:
     * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048
     */
    private static class NullCapableDateFormatter extends DateFormatter
    {
        public NullCapableDateFormatter(DateFormat dateFormat)
        {
            super( dateFormat);
        }

        public Object stringToValue(String string)
                throws ParseException
        {
            if(string == null || string.length() == 0)
            {
                return null;
            }
            return super.stringToValue(string);
        }
    }

Does the author agree with this fix?