我能够使JFrame完全透明,JButton部分透明,直到我在按钮上移动鼠标(不要单击)并从按钮移开鼠标(通过MouseListener调用MouseExited).会发生什么是JButton的背景再次被绘制,所以在按钮上打开和关闭几个鼠标后,按钮完全不透明.
public class ButtonExample extends JWindow
{
public ButtonExample( )
{
JButton But = new JButton( "Testing" );
But.setBackground( new Color( 0, 0, 0, 200 ) );
But.setForeground( new Color( 70, 155, 255 ) );
this.add( But );
this.setBackground( new Color( 0, 0, 0, 0 ) );
this.setMinimumSize( new Dimension( 200,100 ) );
this.setVisible( true );
}
public static void main( String[ ] Args )
{
new ButtonExample( );
}
}
Run Code Online (Sandbox Code Playgroud)