I know you can pass a format to JFormattedTextField constructor, but how would you change the formatter at runtime? For example I have a field that is supposed to be formated to integer values, but when a value of a certain combo box is changed, now the field is supposed to take float values.
I know you can pass a format to JFormattedTextField constructor, but how would you
Share
You could invoke setFormatterFactory(JFormattedTextField.AbstractFormatterFactory) on your object.
You can use it in this fashion:
So just set the factory when your event occurs.
Note that the constructor of
DefaultFormatterFactorycan take several formatters; a default one, a display format when it doesn’t have focus, an edit format when it has focus, and a null format for when the field has a null value.