List of usage examples for javax.swing JFormattedTextField setValue
@BeanProperty(visualUpdate = true, description = "The value to be formatted.") public void setValue(Object value)
AbstractFormatter
obtained from the current AbstractFormatterFactory
. From source file:Main.java
public static void main(String[] argv) throws Exception { JFormattedTextField tft2 = new JFormattedTextField(new DecimalFormat("#.0")); tft2.setValue(new Float(123.4F)); // Retrieve the value from the text field Float floatValue = (Float) tft2.getValue(); }
From source file:Main.java
public static void main(String[] argv) { JFormattedTextField tft1 = new JFormattedTextField(NumberFormat.getIntegerInstance()); tft1.setValue(new Integer(123)); Integer intValue = (Integer) tft1.getValue(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFormattedTextField tft3 = new JFormattedTextField(new SimpleDateFormat("yyyy-M-d")); tft3.setValue(new Date()); Date date = (Date) tft3.getValue(); }
From source file:Main.java
public static void main(String[] argv) { JFormattedTextField f = new JFormattedTextField(new SimpleDateFormat("yyyy-M-d")); f.setValue(new Date()); DateFormatter fmt = (DateFormatter) f.getFormatter(); fmt.setFormat(new SimpleDateFormat("d/M/yyyy")); f.setValue(f.getValue());/*from w w w . ja va 2s .c o m*/ }
From source file:Main.java
public static void main(String[] argv) { JFormattedTextField tft2 = new JFormattedTextField(DateFormat.getDateInstance(DateFormat.SHORT)); tft2.setValue(new Date()); }
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);/* w w 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:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); final JFormattedTextField textField1 = new JFormattedTextField(new Float(10.01)); textField1.setFormatterFactory(new AbstractFormatterFactory() { @Override//from w w w . java 2 s. c o m public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setMaximumFractionDigits(2); numberFormat.setMaximumFractionDigits(2); numberFormat.setRoundingMode(RoundingMode.HALF_UP); final JFormattedTextField textField2 = new JFormattedTextField(numberFormat); textField2.setValue(new Float(10.01)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(textField1, BorderLayout.NORTH); frame.add(textField2, BorderLayout.SOUTH); frame.setVisible(true); frame.pack(); }
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 w w w. j a va2s . 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); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Box form = Box.createVerticalBox(); form.add(new JLabel("Name:")); form.add(new JTextField("User Name")); form.add(new JLabel("Birthday:")); JFormattedTextField birthdayField = new JFormattedTextField(new SimpleDateFormat("MM/dd/yy")); birthdayField.setValue(new Date()); form.add(birthdayField);/* w ww . j a v a 2 s . com*/ form.add(new JLabel("Age:")); form.add(new JFormattedTextField(new Integer(32))); form.add(new JLabel("Hairs on Body:")); JFormattedTextField hairsField = new JFormattedTextField(new DecimalFormat("###,###")); hairsField.setValue(new Integer(100000)); form.add(hairsField); form.add(new JLabel("Phone Number:")); JFormattedTextField phoneField = new JFormattedTextField(new MaskFormatter("(###)###-####")); phoneField.setValue("(314)888-1234"); form.add(phoneField); JFrame frame = new JFrame("User Information"); frame.getContentPane().add(form); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2);//from w w w.j av a 2 s.c om format.setMinimumFractionDigits(2); format.setParseIntegerOnly(true); format.setRoundingMode(RoundingMode.HALF_UP); NumberFormatter formatter = new NumberFormatter(format); formatter.setMaximum(1000); formatter.setMinimum(0.0); formatter.setAllowsInvalid(false); // formatter.setOverwriteMode(false); JFormattedTextField tf = new JFormattedTextField(formatter); tf.setColumns(10); tf.setValue(123456789.99); JFormattedTextField tf1 = new JFormattedTextField(formatter); tf1.setValue(1234567890.99); JFormattedTextField tf2 = new JFormattedTextField(formatter); tf2.setValue(1111.1111); JFormattedTextField tf3 = new JFormattedTextField(formatter); tf3.setValue(-1111.1111); JFormattedTextField tf4 = new JFormattedTextField(formatter); tf4.setValue(-56); JFrame frame = new JFrame("Test"); frame.setLayout(new GridLayout(5, 0)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(tf); frame.add(tf1); frame.add(tf2); frame.add(tf3); frame.add(tf4); frame.pack(); frame.setVisible(true); }