Home arrow static arrow Java Programming [Archive] - JFormattedTextField.setFormatter() doesn't work
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - JFormattedTextField.setFormatter() doesn't work
This topic has 2 replies on 1 page.

Posts:3,369
Registered: 24.10.97
JFormattedTextField.setFormatter() doesn't work  
Aug 3, 2004 1:59 AM



 
I have a custom formatted text field to display date/time values. If i set a format during construction, this format is used. However, if i try to set the format after instantiation via setFormatter(), it doesn't work. I also tried to set the formatter in the constructor (for testing purpose) and it shows, that the format set by setFormatter() is not used:

public class DateField extends JFormattedTextField {...    /**     * Constructor.     */    public DateField() {        super(new SimpleDateFormat("yyyy HH:mm:ss")); //works        setFormatter(new DateFormatter(new SimpleDateFormat("HH:mm:ss"))); //ignored    }//DateField()


The result is, that only the format set via the super() call is used. Any subsequent setFormatter() calls have no effect. Is this a bug or am i something missing here?
 

Posts:3,369
Registered: 24.10.97
Re: JFormattedTextField.setFormatter() doesn't work  
Aug 3, 2004 3:17 AM (reply 1 of 2)



 
My workaround:

    /**     * Set DateFormat.     *      * @param format DateFormat to set.     */    public void setFormat(DateFormat format) {        setFormatterFactory(new DefaultFormatterFactory(new DateFormatter(format)));    }//setFormat()
 

Posts:4,496
Registered: 19/06/02
Re: JFormattedTextField.setFormatter() doesn't work  
Aug 3, 2004 3:36 AM (reply 2 of 2)



 
Set the AbstractFormatterFactory which will be queried for the AbstractFormatter. You should not invoke the setFormatter method.
 
This topic has 2 replies on 1 page.