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 undefined. The suggested fix is to: add argument to match JDatePanelImpl(DateModel, Properties). What should be passed in as the properties argument?
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);
}
}
...Runner...
class testDate2 {
public void main(String[] args) {
date2 d1 = new date2();
d1.GUI();
}
}
Step1:- Select Tools->Palette->Swing/AWT Components Step2:- Click 'Add from JAR'in Palette Manager Step3:- Browse to [NETBEANS HOME]\ide\modules\ext and select swingx-0.9.
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());
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 "";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With