如何只显示JCalendar中今天之后的日期 [英] How to show only date after the date of today in JCalendar
问题描述
我试图限制用户仅选择今天之后的日期,或者选择日期之后的另一个日期
我在 JCalendar API
可以帮助我的东西,但是我没有我找不到什么..我该怎么办?
i'm trying to limit user to select only the date after today, or select date after another Date
I see on JCalendar API
something that could help me but i didn't find nothing.. how can i do it?
推荐答案
我不认为组件上有一个直接的方式做这个。
我知道的一种方法是使用 setSelectableDateRange(Date from,Date to)
- 当您将日期设置为当前日期时,所有前一天单元格,年/月下降将被禁用。
I do not think there is a straight forward way on the component to do this.
One way, that I know of is to use the setSelectableDateRange(Date from,Date to)
- When you set the from date to current date, all previous day cells, year/month drop downs becomes disabled.
示例:
JCalendar calendar = new JCalendar();
calendar.setSelectableDateRange(new Date(),new SimpleDateFormat("MM-DD-YYYY").parse("05-05-2015"));
PropertyChangeListener calendarChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Date selectedDate = ((JCalendar)evt.getSource()).getDate();
}
};
calendar.addPropertyChangeListener("calendar",calendarChangeListener);
这将禁用在当前日期之前,05/05/2015之后的任何日期的选择
This will disable selection of any date before current date and after 05/05/2015
请注意,此API在其javadoc中未记录。但是,这仍然是一个可以预期的公共设置器。
Note that this API is not documented in their javadoc. But still this is a public setter that works as expected.
编辑,因为你想知道如何 JDateChooser
可以在类似的上下文中使用
EDIT since you want to know how JDateChooser
can be used in similar context
JDateChooser chooser = new JDateChooser();
chooser.getJCalendar().setSelectableDateRange(new Date(),new SimpleDateFormat("MM-DD-YYYY").parse("05-05-2015"));
chooser.getJCalendar().addPropertyChangeListener("calendar",...);
这篇关于如何只显示JCalendar中今天之后的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!