Java Swing Text Format createFormattedDateField(DateFormat dfFormat, boolean bOverwriteMode)

Here you can find the source of createFormattedDateField(DateFormat dfFormat, boolean bOverwriteMode)

Description

Create a date formatted text filed

License

Open Source License

Parameter

Parameter Description
dfFormat - DateFormatter for the field

Return

created JFormattedTextField object

Declaration

public static JFormattedTextField createFormattedDateField(DateFormat dfFormat, boolean bOverwriteMode) 

Method Source Code

//package com.java2s;

import java.text.DateFormat;

import java.util.Date;

import javax.swing.JFormattedTextField;

import javax.swing.text.DateFormatter;

public class Main {
    /**//from  w w w  .  j a  v a2 s  . c  o m
     * Create a date formatted text filed
     * @param dfFormat - DateFormatter for the field
     * @param  - enable or not transferring a focus on ENTER key events
     * 
     * @return created JFormattedTextField object
     *
     * @author Anton Nedbailo
     * @date 17.10.2013
     */
    public static JFormattedTextField createFormattedDateField(DateFormat dfFormat, boolean bOverwriteMode) {
        DateFormatter dfDateFormatter = new DateFormatter(dfFormat);
        dfDateFormatter.setValueClass(Date.class);
        dfDateFormatter.setOverwriteMode(bOverwriteMode);
        // If you want the value to be committed on each keystroke instead of focus lost
        dfDateFormatter.setCommitsOnValidEdit(true);
        JFormattedTextField ftfResult = new JFormattedTextField(dfDateFormatter);
        //contract from
        return ftfResult;
    }
}

Related

  1. buildIntegerField(int min, int max)
  2. checkBoundaryCondition(final int pos, final Position.Bias b0, final Position.Bias[] biasRet, final Element neighboringElement, final boolean isLTR, final boolean toWest, final int start, final int length, final int startParagraph, final int endParagraph, final boolean nextIsLTR)
  3. createFormatter(String s)
  4. createFormatterMask(final String mask)
  5. createIntegerFormatter(int minimum, int maximum)
  6. createMaskFormatter(final String s)