简体   繁体   English

在透明窗口上清除JFrame背景

[英]Clear JFrame background on transparent window

i have a transparent JFrame AWTUtilities.setWindowOpaque(this, false); 我有一个透明的JFrame AWTUtilities.setWindowOpaque(this,false); I have a problem when resizing the window. 调整窗口大小时出现问题。 I need something that could clear the background of the window before drawing on it,I need to make it all the background empty and transparent. 我需要一些可以在绘制窗口之前清除窗口背景的东西,我需要使所有背景都是空白和透明的。 Now the painting is draw over the old background and looks ugly. 现在这幅画是在旧的背景上绘制的,看上去很丑。 I tried to draw a transparent image over the background but i have same issues. 我试图在背景上绘制透明图像,但是我遇到了同样的问题。

If you have an opaque component you're completely responsible for drawing its content. 如果您的组件不透明,则您要完全负责绘制其内容。 The windowing system or AWT does NOTHING to set the background to some defined state. 窗口系统或AWT不会将背景设置为某些已定义状态。

So at least you should do something like the basic Canvas code 所以至少您应该做一些像基本的Canvas代码一样的事情

        g.clearRect(0, 0, width, height);

What exactly do you mean with "transparent". 您所说的“透明”到底是什么意思。 Do you want to look through to the desktop? 您要浏览桌面吗? Do you want to see panel behind your component (then at least it should not be "opaque"). 是否要查看组件后面的面板(那么至少它不应该是“不透明的”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM