[英]JButton alpha background change with mouseover
我想在我的应用程序上有2个按钮,透明背景,我“差点”完成它。
这就是我所做的:
public class PanelMenu extends JPanel{
//VARIABLES
private JButton buttonFightSimulator, buttonMatchUp;
//CONSTRUCTORS
public PanelMenu ()
{
this.setBounds(0,0,240,768);
this.setLayout(new FlowLayout(0, 0, 0));
//BUTTON CREATION
buttonFightSimulator = new JButton("FIGHT SIMULATOR");
buttonMatchUp = new JButton("MATCH UP");
buttonFightSimulator.setBackground(new Color(255,255,255,128));
buttonFightSimulator.setFocusPainted(false);
buttonFightSimulator.setBorderPainted(false);
buttonFightSimulator.setPreferredSize(new Dimension(240,60));
buttonMatchUp.setBackground(new Color(255,255,255,128));
buttonMatchUp.setFocusPainted(false);
buttonMatchUp.setBorderPainted(false);
buttonMatchUp.setPreferredSize(new Dimension(240,60));
add(buttonFightSimulator);
add(buttonMatchUp);
this.setBackground(new Color(0,0,0,90));
}
这就是我的视觉效果:
嗯,这就是我想要的。 但当我将鼠标移到2个按钮上时,就会发生这种情况:
因此,每当鼠标移过它时,首先背景越来越透明,然后我们可以看到两个按钮的文本混合在一起。
提前感谢您的回答。
查看带透明度的背景 ,了解问题的解释和几个解决方案。
基本问题是你的组件是不透明的,但背景具有透明度,这会破坏摆动组件之间的绘画契约,因此你会得到绘画工件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.