Java JFormattedTextField create from DecimalFormat

Description

Java JFormattedTextField create from DecimalFormat

import java.awt.BorderLayout;
import java.text.DecimalFormat;

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

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

      JFormattedTextField input = new JFormattedTextField(new DecimalFormat("#.0"));
      input.setValue(new Float(123.4F));


      frame.add(input, BorderLayout.NORTH);

      frame.add(new JTextField(), BorderLayout.SOUTH);
      frame.setSize(250, 100);// www  . j  a v a2 s. c  om
      frame.setVisible(true);
   }
}



PreviousNext

Related