I want to disable multiple date ranges on a JCalendar. I'm following these steps, but I need to know how can I add multiple date evaluators. Help me please, thanks.
Update: I don't know why I can't disable the dates on my JCalendar. I will leave my code here so you guys can check it.
This is my RangeEvaluator class, modified from this class.
class RangeEvaluator implements IDateEvaluator {
private DateUtil dateUtil = new DateUtil();
@Override
public boolean isSpecial(Date date) {
return false;
}
@Override
public Color getSpecialForegroundColor() {
return null;
}
@Override
public Color getSpecialBackroundColor() {
return null;
}
@Override
public String getSpecialTooltip() {
return null;
}
@Override
public boolean isInvalid(Date date) {
return dateUtil.checkDate(date);
// if the given date is in the range then is invalid
}
/**
* Sets the initial date in the range to be validated.
* @param startDate
*/
public void setStartDate(Date startDate) {
dateUtil.setMinSelectableDate(startDate);
}
/**
* @return the initial date in the range to be validated.
*/
public Date getStartDate() {
return dateUtil.getMinSelectableDate();
}
/**
* Sets the final date in the range to be validated.
* @param endDate
*/
public void setEndDate(Date endDate) {
dateUtil.setMaxSelectableDate(endDate);
}
/**
* @return the final date in the range to be validated.
*/
public Date getEndDate() {
return dateUtil.getMaxSelectableDate();
}
@Override
public String getInvalidTooltip() {
return null;
}
@Override
public Color getInvalidBackroundColor() {
return null;
}
@Override
public Color getInvalidForegroundColor() {
return null;
}
}
Here is how I am using the RangeEvaluator class:
RangeEvaluator evaluator = new RangeEvaluator();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
evaluator.setStartDate(dateFormat.parse("11-09-2014"));
evaluator.setEndDate(dateFormat.parse("15-09-2014"));
jCalendar1.getDayChooser().addDateEvaluator(evaluator);
Am I missing something?. Help me please, Thanks.