Java JFormattedTextField create from NumberFormat

Description

Java JFormattedTextField create from NumberFormat

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);

      Format currency = NumberFormat.getCurrencyInstance(Locale.UK);
      JFormattedTextField input = new JFormattedTextField(currency);
      input.setValue(new Date());
      input.setColumns(20);/*from   w  w  w  .j  a  v a2  s. co m*/

      frame.add(input, BorderLayout.NORTH);

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



PreviousNext

Related