To custom format for JFormattedTextField with a formatter. - Java Swing

Java examples for Swing:JFormattedTextField

Introduction

Have a field to format a date in mm/dd/yyyy format

Demo Code

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.swing.JFormattedTextField;
import javax.swing.text.DateFormatter;

public class Main {

  public static void main(String[] args) {
    DateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy");
    DateFormatter dateFormatter = new DateFormatter(dateFormat);

    JFormattedTextField dobField = new JFormattedTextField();
    dobField = new JFormattedTextField(dateFormatter);

  }/*  w ww  .ja v a2s. c om*/
}

Related Tutorials