我正在尝试将特定日期的图标添加到中JCalendar
,但不能。
我怎样才能做到这一点?
我有以下代码:
final JCalendar calendar = new JCalendar();
JDayChooser day= calendar.getDayChooser();
day.setAlwaysFireDayProperty(true);
day.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
//put icon here
ImageIcon icon = new ImageIcon("icon.png");
JLabel label = new JLabel(icon);
day.add(label);
}
编辑:我想要一天中的图标。
JDayChooser
不支持将图标添加到a的按钮。您必须扩展JDayChooser
和修改名为的受保护数组中的按钮之一days
。由于专家组已经相当拥挤,因此我不确定效果是否会吸引人。
或者,实现IDateEvaluator
界面并为您选择的日期更改颜色,如here,here和分发中的其他实现类所示。该课程com.toedter.calendar.demo.BirthdayEvaluator
说明了该方法。
public boolean isSpecial(Date date) {
calendar.setTime(date);
return calendar.get(Calendar.MONTH) == yourSpecialMonth
&& calendar.get(Calendar.DAY_OF_MONTH) == yourSpecialDay;
}
public Color getSpecialForegroundColor() {
return yourSpecialForegroundColor;
}
public Color getSpecialBackroundColor() {
return yourSpecialBackroundColor;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句