Reputation: 3439
Here I am using JMonthChooser and JYearChooser. So how to Change BackGround of JMonthChooser and JYearChooser is there any Idea. how to do it.
I am using Netbeans.
Upvotes: 0
Views: 1321
Reputation: 1
Actually JCalender is made of multiple components.
So, if you want to change background or foreground of it, then first you have to traverse from all different subcomponents of it and then change each's background color.
In my case:
JDateChooser jdatechooser = new JDateChooser();
//to change background color : <br>
for( Component c : jDateChooser1.getComponents()){<br>
((JComponent)c).setBackground(Color.YELLOW); // whatever color you want to choose<br>
}
Upvotes: 0
Reputation: 172
I assume that you use toedter's JCalendar, that you can add to NetBeans'palette.
In this case you have to make it in 3 times for a WHITE background, 2 for other background's colors(3rd point of the belowed list is not useful in this case).
get the JCombobox (Java Component). You have to cast it into a JComboBox because the method getComboBox()
returns a java.awt.Component
.
javax.swing.JComboBox box = (javax.swing.JComboBox) monthChooser.getComboBox();
Modify the JComboBox's Renderer to change list's background (more examples here).
box.setRenderer(new javax.swing.DefaultListCellRenderer() {
@Override
public void paint(java.awt.Graphics g) {
setBackground(new java.awt.Color(255, 255, 255));
setForeground(java.awt.Color.BLACK);
super.paint(g);
}
});
Set the "collapsed list" (selected) background (WHITE only)
box.setOpaque(false);
Hope that help.
Upvotes: 0