Have field to format a number in $#0,000.00 format for JFormattedTextField - Java Swing

Java examples for Swing:JFormattedTextField

Description

Have field to format a number in $#0,000.00 format for JFormattedTextField

Demo Code

import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.swing.JFormattedTextField;
import javax.swing.text.NumberFormatter;

public class Main {

  public static void main(String[] args) {
    NumberFormat numFormat = new DecimalFormat("$#0,000.00");
    NumberFormatter numFormatter = new NumberFormatter(numFormat);
    JFormattedTextField dobField = new JFormattedTextField();

    dobField = new JFormattedTextField(numFormatter);

  }/*  www.j  a  v  a  2s  . c o m*/
}

Related Tutorials