Chinthaka Dinadasa
Chinthaka Dinadasa

Reputation: 3461

Add specific background colors to JDaychooser Dates

I've developed a Java Swing application..

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

Thanks

Upvotes: 1

Views: 3036

Answers (3)

Chinthaka Dinadasa
Chinthaka Dinadasa

Reputation: 3461

    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

Upvotes: 1

trashgod
trashgod

Reputation: 205785

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.

Upvotes: 1

aran
aran

Reputation: 11830

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.

Upvotes: 2

Related Questions