java - How do i use a MaskFormatter on a JFormattedTextField without knowing the length of the string? -


so have jformattedtextfield , need restrict user entering letters , hyphens. i'm not quite sure how use maskformatter without explicitly knowing length of string entered.

my code looks this:

maskformatter formatter = new maskformatter(); formatter.setvalidcharacters("abcdefghijklmnopqrstuvwxyzabscedfghijklmnopqrstuvwxyz-"); jformattedtextfield firstnametextfield = new jformattedtextfield(formatter); 

when call firstnametextfield.settext(getname()), text not set, leaving me unusable, empty text field.

any appreciated. thanks.

since want no commitment in terms of string length, have impression, lot easier achieve effect of jformattedtextfield , maskformatter, if use regular jtextfield , keylistener keyadapter. can check each keystroke against allowed character string , either accept character or beep.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -