setBackground not working in Swing or AWT

I tried to change the background color of the JLabel control.

I tried lots of time, gone through JAVA documentation but it doesn’t helped much. After digging i found that few controls in JAVA have transparent background color and therefore controls having transparent background does not work for the setBackground() property.

To set the background color of such controls, we need to explicitly set the Opaque to true.

JLabel lblMousePointer.setBackground(Color.white);
lblMousePointer.setOpaque(true);

Posted

in

by

Tags:


Related Posts

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading