jpanel透明度问题
我有一个深灰色jpanel
,上面有jlabel
。我将设置为新的颜色(0,0,0,.5f)
(tranparent)作为jlabel
的背景,我使用按钮几次更改文本。问题是,每次更改文本时,先前的文本仍然保留在新文本后面。我将文本从“ 123456789”更改为“ 1234567”,“ 12345”和“ 123”。这是屏幕截图:
我如何摆脱此“影子”?
I have a dark-gray JPanel
with a JLabel
on it. I set new Color(0, 0, 0, .5f)
(tranparent) as the background of the JLabel
and I change the text several times using a button. The problem is, everytime the text is changed, the previous text still remains behind the new text. I change the text from "123456789" to "1234567", "12345" and "123". Here is the screenshot:
How do I get rid of this "shadow"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
秋千不支持透明背景。
Swing期望要么一个组件是:
setopaque(...)
方法用于控制组件的不透明属性。无论哪种情况,这都确保删除任何绘画文物,并可以正确完成自定义绘画。
如果您想使用变形,则需要进行自定义绘画,以确保背景已清除。
面板的自定义绘画将是:
使用透明度的每个组件都需要类似的代码。
或者,您可以查看带有透明度的背景用于自定义可以在任何可以为您完成上述工作的组件上使用的类。
Swing does not support transparent backgrounds.
Swing expects a component to be either:
The
setOpaque(...)
method is used to control the opaque property of a component.In either case this makes sure any painting artifacts are removed and custom painting can be done properly.
If you want to use tranparency, then you need to do custom painting yourself to make sure the background is cleared.
The custom painting for the panel would be:
Similar code would be required for every component that uses transparency.
Or, you can check out Background With Transparency for custom class that can be used on any component that will do the above work for you.
此相关的示例也使
jpanel
半透明。This related example also makes the
JPanel
translucent.尝试一下,也许它将解决您的问题:
在ActionPeroformed中。
try this, maybe it will solve your problem:
In actionPeroformed..