How do I implement JDatePicker

前端 未结 2 1254
攒了一身酷
攒了一身酷 2020-11-30 05:51

I am working with the latest release 1.3.4 of JDatePicker. How should it be implemented?

I get a compiler error: The constructor JDatePanelImpl(UtilDateModel) is und

相关标签:
2条回答
  • 2020-11-30 06:44

    Assuming you are using 1.3.4, then the constructor requirements have changed...

    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());
    

    enter image description here

    Using this 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 "";
        }
    
    }
    
    0 讨论(0)
  • 2020-11-30 06:52

    Just use properties in the constructor of JDatePanelImpl

    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);
    
    0 讨论(0)
提交回复
热议问题