半透明的JLabel没有正确显示背景 [英] Translucent JLabel not properly showing background

查看:155
本文介绍了半透明的JLabel没有正确显示背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下几行:

        label.setBackground(new java.awt.Color(0, 150, 0, 50));

我把它放在MouseAdapter中的mouseReleased方法中。

I place this in a mouseReleased method within a MouseAdapter.

基本上,当我点击它时,我想让标签以半透明的绿色突出显示。

Basically, I want to make the label highlight itself in translucent green when I click on it.

我在面板中有几个标签,所有这些都有这个MouseAdapter添加到它们。

I have several labels in a panel, all with this MouseAdapter added to them.

我的问题是:

- 当我点击标签时,它显示半透明的绿色,但它显示的是另一个JLabel的背景,而不是我点击的那个。

-When I click on the label, it shows the translucent green color, but it is showing the background of ANOTHER JLabel, not the one I click on.

无论我点击哪个标签,它总是描绘背景相同标签。

No matter which label I click on, it always paints the background of the same label.

- 每当我点击标签时,它都会重复相同的背景。
-奇怪的是,每次点击JLabel时,绿色的不透明度似乎都会增加,就好像每次点击一个新的JLabel时,它都会将半透明的绿色涂在自身上。

-Whenever I click on a label, it repeats the same background. -Weirdly, every time I click on a JLabel, the opacity of the green color seems to increase, as if it were painting the translucent green over itself each time I click on a new JLabel.

有关正在发生的事情的任何提示?我应该尝试在此发布SSCCE吗?或者是否有一个我想念的简单答案。我之前没有发布SSCCE的原因是我的代码很大并且分布在多个文件中,所以我必须首先修改它。

Any tips on what's going on? Should I try to post an SSCCE on this? Or is there a simple answer I'm missing. The reason that I didn't post an SSCCE yet is that my code is large and spread across multiple files, so I must trim it out first.

推荐答案

请参阅透明度背景可能的问题和几个解决方案。

See Backgrounds With Transparency for the probable problem and a couple of solutions.

这篇关于半透明的JLabel没有正确显示背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆