Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent JFrame background

Is it possible to make a JFrame that has a transparent background and draw an image on it, so only the image will be visible with no border or background?

like image 636
user Avatar asked Mar 28 '10 16:03

user


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


2 Answers

Yes, it's possible in many ways. This is one of them:

setUndecorated(true);
setBackground(new Color(1.0f,1.0f,1.0f,0.5f));

4th float (which I set to 0.5f) in Color's constructor is alpha channel. It can be 0.0f - 1.0f depend on transparency you want.

like image 166
Punyapat Avatar answered Oct 27 '22 00:10

Punyapat


See Translucent and Shaped Swing Windows by Kirill Grouchnikov.

like image 29
McDowell Avatar answered Oct 27 '22 01:10

McDowell