【发布时间】:2014-08-06 14:04:59
【问题描述】:
我想在我的应用程序上设置 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 个按钮上时,会发生这种情况:
因此,每次鼠标移到背景上时,背景都会变得越来越不透明,然后我们可以看到两个按钮的文本混合在一起。
提前感谢您的回答。
【问题讨论】:
-
你尝试过 repaint()
-
@madhawa priyashantha not JButton 有三种状态
标签: java swing background jbutton alpha