1

In my project I am using com.toedter.calendar.JCalendar class. But I do not know how can I get date when date is chosen.

JDateChooser and JXDatePicker met my need. There is a code that provides date when a date is chosen from JDateChooser.

JDateChooser picker=new JDateChooser();

picker.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            setDate(picker.getDate());
        }
 }); 
Kai
  • 38,985
  • 14
  • 88
  • 103
olyanren
  • 1,448
  • 4
  • 24
  • 42
  • 2
    Hi. I am not familiar with this class. But I have tried [SwingX](http://java.net/projects/swingx/) were is fantastic JXDatePicker. Which should do what you want. PS: Try to provide us with a link to your class then someone can take a look at it. – Boro Apr 23 '11 at 09:47
  • Thanks a lot, I will check SwingX now. The JCalender Class javadoc :http://www.toedter.com/en/jcalendar/api/com/toedter/calendar/JCalendar.html – olyanren Apr 23 '11 at 10:22
  • Boro how can I thank you I do not know. Thank you very much. JXDatePicker class met what I need. – olyanren Apr 23 '11 at 10:35

6 Answers6

4

You definitely want addPropertyChangeListener(), but you need to check getNewValue(). There's a good example here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
2

I am not familiar with this class. But I have tried SwingX were is fantastic JXDatePicker. Which should do what you want.

Here you can see introduction to the JXDatePicker where are nice images showing its capability etc.

PS: Try to provide us with a link to your class then someone can take a look at it.

All the best, Boro.

Boro
  • 7,913
  • 4
  • 43
  • 85
  • Can you suggest a link? Something with a picture might be appealing. – trashgod Apr 23 '11 at 19:42
  • @trashgod thanks for pointing that out. I thought the link was there, my bad. Now there is link to SwingX library + some JXDatePicker intro which was helpful to me when I was starting using it. All good – Boro Apr 24 '11 at 05:27
  • Sweet! The screen shot is especially helpful for future reference. +1, btw. – trashgod Apr 24 '11 at 05:36
1
myDatChooser.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                //some stuff
            }
        });
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • addChangeListener method does not exist in JCalendar class – olyanren Apr 23 '11 at 16:30
  • http://www.toedter.com/en/jcalendar/api/com/toedter/calendar/JDateChooser.html#propertyChange%28java.beans.PropertyChangeEvent%29 – mKorbel Apr 23 '11 at 20:34
  • but that's long time and I used sourceCode (and there I must changed Focus, i18, add Fore/BackGround, disabled Color and put something correctly to the EDT) – mKorbel Apr 23 '11 at 20:44
0
JCalendar cal = new JCalendar();
JLabel label = new JLabel("label");
label.setText(cal.getDate().toString());
      cal.addPropertyChangeListener(new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
              label.setText(cal.getDate().toString());
          }
      });
robertbeb
  • 1,520
  • 1
  • 10
  • 13
0

Have not used it myself, but according the javadoc:

http://www.toedter.com/en/jcalendar/api/com/toedter/calendar/JCalendar.html

there seems to be a getDate() method. Does not this work?

Datoraki
  • 1,223
  • 13
  • 26
  • 1
    It works but there has to be correct event occurrence. Thats which event occurs when choosing day ? I do not know. – olyanren Apr 23 '11 at 10:07
0

Have you tried getDate() method ? I think it will easy your requested mission.

Master C
  • 1,536
  • 4
  • 14
  • 19