[英]How to show only date after the date of today in JCalendar
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?我试图将用户限制为仅在今天之后的日期使用 select,或者在我在JCalendar API上看到的另一个
Date
之后的 select 日期可以帮助我,但我什么也没找到..我该怎么做?
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.我知道的一种方法是使用
setSelectableDateRange(Date from,Date to)
- 当您将起始日期设置为当前日期时,所有前一天的单元格、年/月下拉菜单将被禁用。
Example:例子:
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);
This will disable selection of any date before current date and after 05/05/2015这将禁止选择当前日期之前和 05/05/2015 之后的任何日期
Note that this API is not documented in their javadoc.请注意,这个 API 没有记录在他们的 javadoc 中。 But still this is a public setter that works as expected.
但这仍然是一个按预期工作的公共设置器。
EDIT since you want to know how JDateChooser
can be used in similar context编辑,因为您想知道如何在类似的上下文中使用
JDateChooser
JDateChooser chooser = new JDateChooser();
chooser.getJCalendar().setSelectableDateRange(new Date(),new SimpleDateFormat("MM-DD-YYYY").parse("05-05-2015"));
chooser.getJCalendar().addPropertyChangeListener("calendar",...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.