Transparent JFrame Background

Is it possible to create a JFrame with a transparent background and draw an image on it so that only the image will be visible without a frame or background?

+7
java transparency background-image jframe
source share
5 answers
+9
source share

Yes, this is possible in many ways. This is one of them:

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

The 4th float (which is set to 0.5f) in the Color constructor is the alpha channel. It can be 0.0f - 1.0f depending on the transparency you want.

+10
source share

Maybe.

If your JFrame is a local variable or field:

 myJFrame.setUndecorated(true); 

If your class extends JFrame:

 setUndecorated(true); 
+1
source share

You should also make the content pane transparent.

 frame.setUndecorated(true); frame.getContentPane().setBackground(new Color(1.0f,1.0f,1.0f,0.0f)); frame.setBackground(new Color(1.0f,1.0f,1.0f,0.0f)); 
+1
source share

For an example of Mac OS X, see the Paint Problem on a Translucent Frame / Panel / Component .

0
source share

All Articles