我正在使用最新版本的JDatePicker 1.3.4。应该如何实现?

我收到一个编译器错误:构造函数JDatePanelImpl(UtilDateModel)未定义。建议的解决方法是:添加参数以匹配JDatePanelImpl(DateModel,Properties)。应该将什么作为属性参数传入?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import java.util.Calendar;
import java.util.Date;
import org.jdatepicker.impl.*;
import org.jdatepicker.util.*;
import org.jdatepicker.*;

    //import org.jdatepicker.graphics.*;
class date2 {

    void GUI() {
        JFrame f1 = new JFrame();
        f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f1.setSize(300, 300);
        f1.setVisible(true);

        Container conn = f1.getContentPane();
        conn.setLayout(null);

        UtilDateModel model = new UtilDateModel();
        //model.setDate(20,04,2014);
        JDatePanelImpl datePanel = new JDatePanelImpl(model);
        JDatePickerImpl datePicker = new JDatePickerImpl(datePanel);
        f1.add(datePicker);

    }

}

运行者
class testDate2 {

    public void main(String[] args) {

        date2 d1 = new date2();
        d1.GUI();

    }

}

最佳答案

假设您使用的是1.3.4,则构造函数要求已更改...

UtilDateModel model = new UtilDateModel();
//model.setDate(20,04,2014);
// Need this...
Properties p = new Properties();
p.put("text.today", "Today");
p.put("text.month", "Month");
p.put("text.year", "Year");
JDatePanelImpl datePanel = new JDatePanelImpl(model, p);
// Don't know about the formatter, but there it is...
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter());

使用此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 "";
    }

}

07-24 09:37