0

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.enter image description here

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Kishan Bheemajiyani
  • 3,429
  • 5
  • 34
  • 68
  • 1
    I don't believe these are standard Swing components in the JDK, can you supply a link to the javadocs for those components to identify what those are? If they are like most Swing components there's a setBackgroundColor method, if that doesn't work because you're using Nimbus (I think you are at least, and I think Nimbus blocks setting the background color on some components) then you can check out how to [change your Nimbus Color Theme](http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/color.html) – NESPowerGlove Mar 06 '14 at 15:57
  • nope but i just want to Change that Background of that JMonthChooser. – Kishan Bheemajiyani Mar 06 '14 at 19:21
  • Well, you're still going to have to post some documentation on what a JMonthChooser is for any help. – NESPowerGlove Mar 06 '14 at 20:03
  • Its nothing its Tool i means Jcalander 1.3.2 jar Controls which u can add in Netbeans. pellate. – Kishan Bheemajiyani Mar 06 '14 at 20:16

2 Answers2

0

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).

  1. 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();
    
  2. 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);
         }
     });
    
  3. Set the "collapsed list" (selected) background (WHITE only)

    box.setOpaque(false);
    

Hope that help.

Community
  • 1
  • 1
Fabien
  • 173
  • 2
  • 9
0

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>
}
Butiri Dan
  • 1,759
  • 5
  • 12
  • 18