开发者

Transparent JFrame background

开发者 https://www.devze.com 2022-12-24 04:57 出处:网络
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?Yes, it\'s possible in many way

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?


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.


See Translucent and Shaped Swing Windows by Kirill Grouchnikov.


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


It is possible.

If your JFrame is a local variable or field:

myJFrame.setUndecorated(true);

If your class extends JFrame:

setUndecorated(true);


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


setOpacity(0.50f);//50% opaque

0

精彩评论

暂无评论...
验证码 换一张
取 消