How init JCalendar with no default date

881 Views Asked by At

i'm using JCalendar and i initialize it in this way:

popup = new JPopupMenu();
calendar = new JCalendar();
popup.add(calendar);
calendar.addDateListener(new DateListener() {
    @Override
    public void dateChanged(DateEvent de) {
       Calendar c = de.getSelectedDate();
       if (c != null) {
          String data = c.get(Calendar.DAY_OF_MONTH) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.YEAR);
          dateTextField.setText(data);
          popup.setVisible(false);
       }
    }
});
dateTextField.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
        popup.show(e.getComponent(), e.getX(), e.getY());
        popup.setVisible(true);  
    }
});

In this way when i click on the textfield dateTextField it shows popup with JCalendar but it show me today's date selected and if i want to show that date in my textfield i have to choose another date and then choose another time today's date. How can i remove default selected date? thanks!!!

1

There are 1 best solutions below

0
On

It appears there isn't a way to do exactly what you want using JCalendar. One alternative could be to add a "Done" button to your popup that would grab the currently selected date, set the button text, and close the popup. That might be more intuitive for the user anyway, since it could be a little confusing for the popup to close if they accidentally click on the wrong date.