List of usage examples for javax.swing.text MaskFormatter MaskFormatter
public MaskFormatter(String mask) throws ParseException
MaskFormatter
with the specified mask. From source file:Main.java
public static void main(String args[]) throws Exception { MaskFormatter mf = new MaskFormatter("A-AAAA-AAAA-A"); mf.setValueContainsLiteralCharacters(false); System.out.println(mf.valueToString("123123123123")); }
From source file:Main.java
public static void main(String[] argv) throws Exception { MaskFormatter fmt = new MaskFormatter("###-###-####"); JFormattedTextField tft1 = new JFormattedTextField(fmt); }
From source file:Main.java
public static void main(String[] argv) throws Exception { MaskFormatter fmt = new MaskFormatter("###-###-####"); JFormattedTextField tft1 = new JFormattedTextField(fmt); fmt = new MaskFormatter("###-##-####"); JFormattedTextField tft2 = new JFormattedTextField(fmt); }
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 w w .j av a 2 s .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); }
From source file:Main.java
public static void main(String args[]) throws ParseException { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); MaskFormatter mf1 = new MaskFormatter("###-###-###"); mf1.setPlaceholderCharacter('_'); JFormattedTextField ftf1 = new JFormattedTextField(mf1); content.add(ftf1);/*from ww w. ja v a 2 s.c o m*/ MaskFormatter mf2 = new MaskFormatter("(###) ###-####"); JFormattedTextField ftf2 = new JFormattedTextField(mf2); content.add(ftf2); f.setSize(300, 100); f.setVisible(true); }
From source file:MainClass.java
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 {//from w w w .j av a2s. com MaskFormatter mf1 = new MaskFormatter("(###) ###-####"); rowOne.add(new JFormattedTextField(mf1)); } catch (ParseException e) { } f.add(rowOne, BorderLayout.NORTH); f.setSize(300, 100); f.setVisible(true); }
From source file:MainClass.java
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 {/*from ww w . j a va2s . c o m*/ MaskFormatter mf1 = new MaskFormatter("###-##-####"); rowOne.add(new JFormattedTextField(mf1)); } catch (ParseException e) { } f.add(rowOne, BorderLayout.NORTH); f.setSize(300, 100); f.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Mask Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;//from w w w . j ava 2 s. c o m JFormattedTextField input; JPanel panel; MaskFormatter formatter; try { label = new JLabel("US Phone"); formatter = new MaskFormatter("'(###')' ###'-####"); formatter.setPlaceholderCharacter('*'); input = new JFormattedTextField(formatter); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); } catch (ParseException e) { System.err.println("Unable to add Phone"); } frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(100, 75);// ww w. j a va2 s. co m JPanel content = new JPanel(new FlowLayout()); frame.setContentPane(content); MaskFormatter formatter = new MaskFormatter("#"); formatter.setValidCharacters("123456789"); JFormattedTextField f1 = new JFormattedTextField(formatter); f1.setValue(null); f1.setColumns(1); content.add(f1); frame.setVisible(true); }
From source file:MaskInputSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Mask Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;//from w ww . ja va2 s. com JFormattedTextField input; JPanel panel; MaskFormatter formatter; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); try { label = new JLabel("SSN"); formatter = new MaskFormatter("###'-##'-####"); input = new JFormattedTextField(formatter); input.setValue("123-45-6789"); input.setColumns(20); panel = new JPanel(); panel.add(label); panel.add(input); frame.add(panel); } catch (ParseException e) { System.err.println("Unable to add SSN"); } frame.pack(); frame.setVisible(true); }