Transparent JFrame background

不想你离开。 提交于 2019-12-21 11:22:11

问题


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?


回答1:


See Translucent and Shaped Swing Windows by Kirill Grouchnikov.




回答2:


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.




回答3:


It is possible.

If your JFrame is a local variable or field:

myJFrame.setUndecorated(true);

If your class extends JFrame:

setUndecorated(true);



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



回答5:


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



来源:https://stackoverflow.com/questions/2533650/transparent-jframe-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!