Add specific background colors to JDaychooser Dates

佐手、 提交于 2019-11-27 06:30:49

问题


I've developed a Java Swing application..

How can I set the background color of specific JDayChooser dates?

Thanks


回答1:


getDayPanel

public javax.swing.JPanel getDayPanel()

This returns the day panel. After that, you can:

panel.setBackground(color);  

Also:

setForeground

public void setForeground(java.awt.Color foreground)

Sets the foregroundColor color.

setDecorationBackgroundColor

public void setDecorationBackgroundColor(java.awt.Color decorationBackgroundColor)

Sets the background of days and weeks of year buttons.




回答2:


JDayChooser has a protected field that specifies the selectedColor, but it has no public interface. You can,

  • Alter the default gray, in JDayChooser#init().

  • Add the required methods; the new bound property will appear in JCalendarDemo.

    public Color getSelectedColor() {
        return selectedColor;
    }
    
    public void setSelectedColor(Color selectedColor) {
        this.selectedColor = selectedColor;
    }
    

As discussed here, setBackground() doesn't read well on some Look & Feel implementations. The workaround in DecoratorButton#paint() is an example.




回答3:


    JPanel jPanel = jDayChooser1.getDayPanel();

    Component component[] = jPanel.getComponents();

    for (int i = 7; i < 49; i++) {
        component[i].setBackground(Color.red);
    }

Finally got a solution to do :D



来源:https://stackoverflow.com/questions/16234388/add-specific-background-colors-to-jdaychooser-dates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!