Java JFormattedTextField create from double type value

Description

Java JFormattedTextField create from double type value

import java.awt.BorderLayout;
import java.text.Format;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;

import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class Main {
   public static void main(final String args[]) {
      JFrame frame = new JFrame("Formatted Example");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      JFormattedTextField input = new JFormattedTextField(1234.50);
      input.setValue(new Date());
      input.setColumns(20);//from   ww w.j a v a  2  s . c om

      frame.add(input, BorderLayout.NORTH);

      frame.add(new JTextField(), BorderLayout.SOUTH);
      frame.setSize(250, 100);
      frame.setVisible(true);
   }
}



PreviousNext

Related