Java examples for Swing:JTextField
Creating a Text Field to Display and Edit a Phone Number
import javax.swing.JFormattedTextField; import javax.swing.text.MaskFormatter; public class Main { public static void main(String[] args) { MaskFormatter fmt = null;//from w ww . jav a2 s .c o m // A phone number try { fmt = new MaskFormatter("###-###-####"); } catch (java.text.ParseException e) { } JFormattedTextField tft1 = new JFormattedTextField(fmt); // A social security number try { fmt = new MaskFormatter("###-##-####"); } catch (java.text.ParseException e) { } JFormattedTextField tft2 = new JFormattedTextField(fmt); // A social security number fmt.setPlaceholderCharacter('*'); JFormattedTextField tft3 = new JFormattedTextField(fmt); } }