How to make JFrame transparent?

£可爱£侵袭症+ 提交于 2019-11-30 16:57:28

问题


How to make JFrame transparent? I want to make my JFrame transparent. User should see the background when my JFrame is on top of it.


回答1:


I found another solution.

Set the background color of your frame to

// Set the frame background color to a transparent color
yourFrameHere.setBackground(new Color(0, 0, 0, 0));

And remember to set the opacity off of the contentpane (your JPanel or other component)

// turn off opacity of the content pane
yourContentPaneHere.setOpaque(false);



回答2:


If you do not have any objection in using restricted API classes then you can do this with AWTUtilities class and setWindowOpacity() method of that class. Here and here is a tutorial on how to use it? And here is the version using Java native access.



来源:https://stackoverflow.com/questions/6660908/how-to-make-jframe-transparent

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