1

I use mouse click event. When I click to select specific date on it but nothing happened inside mouse click event. I use this code. I don't want to need use JDateChooser

jCalendar.getDayChooser().addPropertyChangeListener("day", new PropertyChangeListener() {
        @Override

        public void propertyChange(PropertyChangeEvent e) {
        System.out.println(e.getPropertyName()+ ": " + e.getNewValue());
    }
});
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
NicoleZ
  • 1,485
  • 3
  • 22
  • 43

2 Answers2

4

I am not sure what do you mean by "e.i doesnt want to need use jDatechooser". To get the date you could use :

jCalendar.getDayChooser().addPropertyChangeListener(
        //property sliderListener detects change of date in date chooser
        (PropertyChangeEvent evt)-> { dateChooserPropertChanged(evt);   });

private void dateChooserPropertChanged(PropertyChangeEvent evt) {

    if ("calendar".equals(evt.getPropertyName())
                || "date".equals(evt.getPropertyName())) {

        System.out.println("date is :"+ jCalendar.getDayChooser().getDate());
    }
}
c0der
  • 18,467
  • 6
  • 33
  • 65
3
    cal = new JCalendar();
    cal.setWeekOfYearVisible(false);
    cal.getDayChooser().addPropertyChangeListener("day", new PropertyChangeListener() {

    @Override
    public void propertyChange(PropertyChangeEvent e) {
        System.out.println(e.getPropertyName()
                + ": " + e.getNewValue());

    }
});

Still, that will only give you the day that the user picked, not the entire date.

Instead of using e.getnewvalue(); , use cal.getDate.toString() so you can show the entire date.

jarvo69
  • 7,908
  • 2
  • 18
  • 28
  • k i will check and do it – NicoleZ Aug 20 '16 at 07:17
  • can i use this code inside my mouse clicked event and can you tell me what is the that "day" means – NicoleZ Aug 20 '16 at 07:45
  • i use your code .it works fine but there is a problem i want to select some date when i clicked on that date in jCalendar .but when i use this jCalendarMouseClicked() nothing happen .but jButtonActionPerformed() code work properly .where is the problem help me – NicoleZ Aug 20 '16 at 09:16
  • this seems helpful to your query: http://stackoverflow.com/questions/7179100/jdatechooser-mouseclicked-event-doesnt-get-fired – jarvo69 Aug 20 '16 at 09:28