我正在尝试将特定日期的图标添加到 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
的按钮添加图标。您必须扩展JDayChooser
并修改名为days
的 protected 数组中的按钮之一。由于小组已经相当拥挤,我不确定效果是否有吸引力。
或者,实现 IDateEvaluator
接口(interface)并更改所选日期的颜色,如 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;
}
关于Java向JCalendar添加图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30696992/