Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make JFrame transparent?

How to make JFrame transparent? I want to make my JFrame transparent. User should see the background when my JFrame is on top of it.

like image 699
Harry Joy Avatar asked Jul 12 '11 07:07

Harry Joy


People also ask

How do I make a transparent jPanel?

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

Is there a transparent color in Java?

The alpha value defines the transparency of a color and can be represented by a float value in the range 0.0 - 1.0 or 0 - 255. An alpha value of 1.0 or 255 means that the color is completely opaque and an alpha value of 0 or 0.0 means that the color is completely transparent.

How do I change the background color of a JFrame?

In general, to set the JFrame background color, just call the JFrame setBackground method, like this: jframe. setBackground(Color. RED);


1 Answers

I found another solution.

Set the background color of your frame to

// Set the frame background color to a transparent color
yourFrameHere.setBackground(new Color(0, 0, 0, 0));

And remember to set the opacity off of the contentpane (your JPanel or other component)

// turn off opacity of the content pane
yourContentPaneHere.setOpaque(false);
like image 71
drzymala Avatar answered Oct 16 '22 02:10

drzymala