簡體   English   中英

用鼠標懸停改變JButton alpha背景

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM