new MaskFormatter('(###) ###-####') (2) : MaskFormatter « javax.swing.text « Java by API






new MaskFormatter('(###) ###-####') (2)

import java.awt.BorderLayout;
import java.text.ParseException;

import javax.swing.Box;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.text.MaskFormatter;

public class MainClass {
  public static void main(String args[]) {
    JFrame f = new JFrame("JFormattedTextField Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Box rowOne = Box.createHorizontalBox();
    rowOne.add(new JLabel("SSN:"));
    try {
      MaskFormatter mf1 = new MaskFormatter("(###) ###-####");
      rowOne.add(new JFormattedTextField(mf1));
    } catch (ParseException e) {
    }
    f.add(rowOne, BorderLayout.NORTH);

    f.setSize(300, 100);
    f.setVisible(true);
  }
}

           
       








Related examples in the same category

1.new MaskFormatter("LLLL")
2.new MaskFormatter("UUUU")
3.new MaskFormatter('###-##-####')
4.MaskFormatter; setPlaceholderCharacter(char placeholder)