List of usage examples for javax.swing.text MaskFormatter setValueClass
public void setValueClass(Class<?> valueClass)
From source file:Main.java
public static void main(String[] args) throws Exception { final MaskFormatter formatter = new TimeFormatter(); formatter.setValueClass(java.util.Date.class); final JFormattedTextField tf2 = new JFormattedTextField(formatter); tf2.setValue(new Date()); final JLabel label = new JLabel(); JButton bt = new JButton("Show Value"); bt.addActionListener(e -> {//from ww w .ja v a 2s .c o m System.out.println(" value 2 = " + tf2.getValue()); System.out.println(" value 2 = " + tf2.getText()); System.out.println("value class: " + formatter.getValueClass()); label.setText(tf2.getText()); }); JFrame f = new JFrame(); f.getContentPane().setLayout(new GridLayout()); f.getContentPane().add(tf2); f.getContentPane().add(label); f.getContentPane().add(bt); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }