JCalendar getting date

匆匆过客 提交于 2019-12-11 07:35:16

问题


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());
        }
 }); 

回答1:


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




回答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.




回答3:


myDatChooser.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                //some stuff
            }
        });



回答4:


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?




回答5:


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




回答6:


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());
          }
      });


来源:https://stackoverflow.com/questions/5763394/jcalendar-getting-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!