简体   繁体   中英

How init JCalendar with no default date

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!!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM