Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Dynamically change the format

import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JFormattedTextField; import javax.swing.text.DateFormatter; public class Main {   public static void main(String[] argv) {     JFormattedTextField f = new JFormattedTextField(new SimpleDateFormat("yyyy-M-d"));     f.setValue(new Date());     DateFormatter fmt = (DateFormatter) f.getFormatter();     fmt.setFormat(new SimpleDateFormat("d/M/yyyy"));     f.setValue(f.getValue());   } }