问题
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