how to make a jtextfield having a fixed date format?

Janpol Seda picture Janpol Seda · Sep 29, 2012 · Viewed 41.8k times · Source

I'm having trouble creating a fixed date format using JTextField. Is there a way for JTextField to have a fixed date format ?

Answer

joval picture joval · Sep 29, 2012

You can use JFormattedTextField with SimpleDateFormat

DateFormat format = new SimpleDateFormat("your_format");
JFormattedTextField dateTextField = new JFormattedTextField(format);