List of usage examples for javax.swing.text MaskFormatter getMask
public String getMask()
From source file:Main.java
public static void main(String[] args) throws Exception { MaskFormatter formatter = new MaskFormatter("###-##-####"); JFormattedTextField tf = new JFormattedTextField(formatter); JPanel panel = new JPanel(new BorderLayout()); panel.add(tf, BorderLayout.NORTH); JButton clickBtn = new JButton("Click me!"); clickBtn.addActionListener(e -> { if (!tf.getText().matches(formatter.getMask())) { System.err.println("Your Input does not match the pattern!"); } else {/*from w ww. j a va 2s .co m*/ System.out.println(tf.getText()); } }); panel.add(clickBtn, BorderLayout.SOUTH); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(panel, BorderLayout.CENTER); f.setSize(800, 600); f.setVisible(true); }