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?
Asked
Active
Viewed 4.3k times
6 Answers
14
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.

Punyapat
- 369
- 3
- 6
-
This is worked for me once I replaced `0.5f` with `0.0f`. Nice Answer. – Hasitha Jayawardana May 07 '19 at 04:58
11
See Translucent and Shaped Swing Windows by Kirill Grouchnikov.
-
8Link is now dead. Google suggests this blog post: http://www.pushing-pixels.org/2008/02/27/translucent-and-shaped-windows-in-core-java.html – Mark Peschel Mar 04 '18 at 20:59
4
You should make content pane transparent too.
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));

ossobuko
- 851
- 8
- 25
1
It is possible.
If your JFrame is a local variable or field:
myJFrame.setUndecorated(true);
If your class extends JFrame:
setUndecorated(true);

Michael
- 1,239
- 9
- 14

Taylor Golden
- 39
- 1
- 7
-
2true that since jdk7, transparency is only supported for undecorated frames. How to call methods should be basic knowledge, though :-) – kleopatra Oct 21 '12 at 09:19