Java将图标添加到JCalendar

劳伦索·贡萨尔维斯(LourençoGonçalves)

我正在尝试将特定日期的图标添加到中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界面并为您选择的日期更改颜色,如herehere和分发中的其他实现类所示该课程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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章