半透明的JLabel没有正确显示背景

编程入门 行业动态 更新时间:2024-10-28 02:30:11
本文介绍了半透明的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没有正确显示背景

本文发布于:2023-11-04 05:55:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557132.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   背景   JLabel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!