1

I've developed a Java Swing application..

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

Thanks

Chinthaka Dinadasa
  • 3,332
  • 2
  • 28
  • 33

3 Answers3

2

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.

aran
  • 10,978
  • 5
  • 39
  • 69
  • 1
    JPanel jPanel = jDayChooser1.getDayPanel(); Component component[] = jPanel.getComponents(); for (int i = 7; i < 49; i++) { component[i].setBackground(Color.red); } – Chinthaka Dinadasa May 09 '13 at 05:49
  • glad you find the solution and thanks for the feedback. + 1 for your answer. Tip: don't forget marking your own answer as correct. It will give you reputation points. – aran May 09 '13 at 07:26
1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1
    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

Chinthaka Dinadasa
  • 3,332
  • 2
  • 28
  • 33