user
user

Reputation: 6797

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?

Upvotes: 9

Views: 44564

Answers (6)

Prakash D
Prakash D

Reputation: 1

setOpacity(0.50f);//50% opaque

Upvotes: 0

McDowell
McDowell

Reputation: 108859

See Translucent and Shaped Swing Windows by Kirill Grouchnikov.

Upvotes: 11

ossobuko
ossobuko

Reputation: 871

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

Upvotes: 4

Punyapat
Punyapat

Reputation: 399

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.

Upvotes: 15

Taylor Golden
Taylor Golden

Reputation: 39

It is possible.

If your JFrame is a local variable or field:

myJFrame.setUndecorated(true);

If your class extends JFrame:

setUndecorated(true);

Upvotes: 1

trashgod
trashgod

Reputation: 205775

For a Mac OS X example, see Re-paint problem on translucent frame/panel/component.

Upvotes: 0

Related Questions