1

I would like to "clear" a JFormattedTextField programmatically but if I simply call txtAny.setText("") it is doesn't work cause textfield's regex pattern in my case:

private final String FORMATTER_STRING_FLOAT =
 "[\\p{Digit}\\p{Cntrl}]{1,32}(\\.[\\p{Digit}\\p{Cntrl}]{0,2})?";
 
that requires at least one digit.

So my question is: how can I obtain a regex pattern of a JFormattedTextField for at least further manual partial processing?

xolmc
  • 323
  • 1
  • 3
  • 7
  • See also http://stackoverflow.com/questions/4148336/jformattedtextfield-is-not-properly-cleared which suggests that (as of Java 5, at least) there are limitations on clearing JFormattedTextField – DNA Feb 23 '12 at 11:27
  • See also [Why is JFormattedTextField Evil?](http://stackoverflow.com/questions/1320117/why-is-jformattedtextfield-evil) – DNA Feb 23 '12 at 11:29
  • should be simple and possible, there isn't reason be confused thread linked by @DNA, depends of your code in the [SSCCE](http://sscce.org/) form – mKorbel Feb 23 '12 at 11:43

1 Answers1

2

Call setText(anyValidString) rather than setText("")

StanislavL
  • 56,971
  • 9
  • 68
  • 98