使 JLabel 背景再次透明
我有一个 JLabel,当鼠标进入它时,它会更改其背景颜色。我遇到的问题是我希望 JLabel 在鼠标退出后变得透明。
我可以使用一个声明来完成此任务吗?
I have a JLabel that changes its background color when the mouse enters it. The problem I have is that I want the JLabel to become transparent after the mouse exits.
Is there a statement I can use to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是德国的一个懒惰的假期,因此结合两个答案:
问题(实际上,我倾向于将其视为错误)是设置不透明属性不会触发适当的重新绘制。 JComponent 触发了一个更改事件,但似乎没有人在听:
It's a lazy holiday here in Germany, so combining the two answers:
The problem (actually, I tend to regard it as a bug) is that setting the opaque property doesn't trigger a repaint as would be appropriate. JComponent fires a change event, but seems like nobody is listening:
JLabel
默认情况下是透明的并且非不透明,如果你想在鼠标退出时更改背景,那么你必须:setBackground( )
对于两种状态,进入和退出更改为
JPanel
或其他JComponent
JLabel
is by default transparent and non-opaque, if you want to change background on mouse exit, then you have to:setBackground()
for both states, enter and exitchange to
JPanel
or anotherJComponent