用的JButton鼠标悬停阿尔法背景变化 [英] JButton alpha background change with mouseover

查看:452
本文介绍了用的JButton鼠标悬停阿尔法背景变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要对我的应用程序2个按钮具有透明背景和我几乎做到了。

I want to have 2 buttons on my application with a transparent background and I "almost" done it.

这是我干了什么:

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));
}

这是我在视觉上有:

And this is what I visually have :

嗯,这是伟大的,这就是我想要的。但是,当我通过我的鼠标在2个按钮,这是发生什么:

Well that's great that's what I wanted. But when I pass my mouse over the 2 buttons, this is what happen :

因此​​,首先在后台每次都遇到越来越少透明在它的鼠标移动,然后我们可以看到,两个按钮的文本混合在一起。

So first the background get less and less transparent every time the mouse moves over it and then we can see that the text of the both buttons are mixed together.

感谢您提前为你的答案。

Thank you in advance for your answer.

推荐答案

检查出的背景随着透明度对这个问题的解释和一对夫妇的解决方案。

Check out Backgrounds With Transparency for an explanation of the problem and a couple of solutions.

最根本的问题是,你的组件是不透明的,但背景有透明度,使你得到神器画打破Swing组件之间的合同画

The basic problem is that your component is opaque but the background has transparency which breaks the painting contract between swing components so you get painting artifacts.

这篇关于用的JButton鼠标悬停阿尔法背景变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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