问题
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