java JCalendar 获取日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5763394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JCalendar getting date
提问by olyanren
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.
在我的项目中,我正在使用com.toedter.calendar.JCalendar
类。但我不知道如何在选择日期时获得日期。
JDateChooser and JXDatePicker met my need. There is a code that provides date when a date is chosen from JDateChooser.
JDateChooser 和 JXDatePicker 满足了我的需要。当从 JDateChooser 中选择日期时,有一个提供日期的代码。
JDateChooser picker=new JDateChooser();
picker.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
setDate(picker.getDate());
}
});
回答by trashgod
回答by Boro
I am not familiar with this class. But I have tried SwingXwere is fantastic JXDatePicker. Which should do what you want.
我对这门课不熟悉。但是我尝试过SwingX是很棒的 JXDatePicker。哪个应该做你想做的。
Here you can see introduction to the JXDatePickerwhere are nice images showing its capability etc.
在这里你可以看到JXDatePicker 的介绍,其中有很好的图片展示了它的功能等。
PS: Try to provide us with a link to your class then someone can take a look at it.
PS:试着给我们提供一个你班级的链接,然后有人可以看看。
All the best, Boro.
一切顺利,博罗。
回答by mKorbel
myDatChooser.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
//some stuff
}
});
回答by Datoraki
Have not used it myself, but according the javadoc:
自己没用过,但根据javadoc:
http://www.toedter.com/en/jcalendar/api/com/toedter/calendar/JCalendar.html
http://www.toedter.com/en/jcalendar/api/com/toedter/calendar/JCalendar.html
there seems to be a getDate() method. Does not this work?
似乎有一个 getDate() 方法。这行不通?
回答by Master C
Have you tried getDate() method ? I think it will easy your requested mission.
你试过 getDate() 方法吗?我认为这会很容易完成你要求的任务。
回答by robertbeb
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());
}
});