I installed JDatePickerin my application, but I want the date to be formatted as YYYY_MM_DD
Currently, the date format is the default format. There is a class Wed Jul 08 15:17:01 ADT 2015
from this guide that formats the date as follows.
package net.codejava.swing;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JFormattedTextField.AbstractFormatter;
public class DateLabelFormatter extends AbstractFormatter {
private String datePattern = "yyyy-MM-dd";
private SimpleDateFormat dateFormatter = new SimpleDateFormat(datePattern);
@Override
public Object stringToValue(String text) throws ParseException {
return dateFormatter.parseObject(text);
}
@Override
public String valueToString(Object value) throws ParseException {
if (value != null) {
Calendar cal = (Calendar) value;
return dateFormatter.format(cal.getTime());
}
return "";
}
}
So I added the class to my package, and the Swing application has the correct constructor
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter());
, datePicker.getModel().getValue().toString() .
, DateLabelFormatter valueToString, .
?
, ?
[ ?] ?