2012-07-17 16 views
6

私の問題では、私は不透明なJPanelと、最初のJPanel上にある半透明(半透明)のJPanelを持っています。上のJPanelにラジオボタンを追加したとき。問題は、各ラジオボタンのラベルの領域にマウスを置くたびに(ラベルをマウスで移動するたびに)、暗くなり、暗くなります。スイング:半透明のラジオボタンの上にマウスを置いてください。JPanel

私はトップのJPanelにJLabelのを追加した場合、別の機会に、私は、同じ条件であることを観察している、となるように、トップパネルにリスナーを追加し、ので、これはラジオボタンの問題ではありません信じて
package trial; 

import java.awt.Color; 
import javax.swing.ButtonGroup; 
import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.JRadioButton; 

public class Test { 

public static void main(String arg[]){ 
    JFrame rootframe = new JFrame("Test panel"); 
    rootframe.setSize(800, 550); 
    rootframe.setExtendedState(JFrame.MAXIMIZED_BOTH); 

    JPanel basePanel = new JPanel(); //fills rootFrame 
    basePanel.setOpaque(true); 
    basePanel.setBackground(Color.yellow);  

    JPanel panelContainingRadioButtons = new JPanel();//wraps radio buttons 
    panelContainingRadioButtons.setOpaque(true); 
    panelContainingRadioButtons.setBackground(new Color(0,0,0,100)); 

    ButtonGroup buttonGroup1 = new ButtonGroup(); 

    JRadioButton jRadioButton1 = new JRadioButton(); 
    jRadioButton1.setText("Text A..............................."); 
    jRadioButton1.setOpaque(false); 
    jRadioButton1.setForeground(Color.white); 
    buttonGroup1.add(jRadioButton1); 

    JRadioButton jRadioButton2 = new JRadioButton(); 
    jRadioButton2.setOpaque(false); 
    jRadioButton2.setForeground(Color.white); 
    buttonGroup1.add(jRadioButton2); 
    jRadioButton2.setText("Text B......................."); 

    JRadioButton jRadioButton3 = new JRadioButton(); 
    jRadioButton3.setOpaque(false); 
    jRadioButton3.setForeground(Color.white); 
    buttonGroup1.add(jRadioButton3); 
    jRadioButton3.setText("Text C................................"); 

    panelContainingRadioButtons.add(jRadioButton1); 
    panelContainingRadioButtons.add(jRadioButton2); 
    panelContainingRadioButtons.add(jRadioButton3); 

    basePanel.add(panelContainingRadioButtons); 

    rootframe.add(basePanel); 
    rootframe.setVisible(true); 

} 
} 

JLabelのテキストの色テキストは下の画像のように別の場所に再描画されます、マウスがホバーされたときに変更され、ときにマウスが終了orginal色にリセットされます: -

http://s13.postimage.org/6yn3cw48n/Untitled.png

必要に応じて私はそのコードも投稿します。どちらの場合も同じ問題だと思います。

答えて

8

おそらく背景に使用される透明な色のために、これらのペインティングアーチファクトが発生します。 JComponentは透明色を背景色としてサポートしていません。 @camickrによるarticleの詳細は、この問題の詳細を説明し、代替の解決方法も示しています。

+1

+1いい記事です。 – trashgod

+1

正確に私が必要とする..ありがとう! –

4

予期しない結果ではありませんが、デフォルトのGraphics2DのコンビネーションAlphaComposite.SRC_OVERです。別の結果が必要な場合は、別のモードを使用する必要があります。例えば、AlphaComposite.SRCは、でなく、の添加物である。関連する例は、here,hereおよびhereである。

+0

素晴らしい例、+1 – tenorsax

1

赤、緑、青、アルファの代わりに、Eg:setBackground(new Color(236、233、216、220)); setBackground(new Color(236,233,216))を使用します。赤、緑、青である。それは完全に動作します。

関連する問題