Here you can find the source of createFormattedDateField(DateFormat dfFormat, boolean bOverwriteMode)
Parameter | Description |
---|---|
dfFormat | - DateFormatter for the field |
public static JFormattedTextField createFormattedDateField(DateFormat dfFormat, boolean bOverwriteMode)
//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; } }