Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a JPanel not draw its background (Transparent)

Is it possible, in Java, to make a JPanel skip drawing its background thus being transparent except for the components on it?

like image 916
jjnguy Avatar asked Sep 10 '08 18:09

jjnguy


People also ask

Can you make a JPanel transparent?

You can simply create your jPanel using drag and drop, as you always do and then for changing the panel's color and making it transparent or semi-transparent you can use this code: panel. setBackground(new Color(0.0f, 0.0f, 0.0f, 0.5f));

How do I fill a JPanel with color?

We can set a background color to JPanel by using the setBackground() method.

How do I make my background transparent in swing?

The transparency can be set using the setBackground() method. Yes, you might have missed the java. awt. Color class' constructor Color(int r,int g,int b,int a); the last parameter here, does it all.


1 Answers

setOpaque(false)

It'll pass off painting the background to its parent, which may draw its own background.

You can do a screen capture and then use that to paint the background of the panel.

like image 139
Allain Lalonde Avatar answered Sep 21 '22 06:09

Allain Lalonde