While testing the following simple code I see a strange behavior: the button which has a transparent background color, gets more and more opaque, while the mouse enters or exits out of the bounds of the button. What is this strange behavior for? The code is as follows:
public class TransparentColorTest
{
public static void main( String[] args )
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setLayout( new FlowLayout() );
frame.setSize( 200 , 200 );
Color transparentColor = new Color( 0 , 0 , 255 , 20 );
JButton testButton = new JButton();
testButton.setPreferredSize( new Dimension( 100 , 100 ) );
testButton.setBackground( transparentColor );
frame.add( testButton );
frame.setVisible( true );
}
}
The fourth argument to the Color constructor, determines the transparency of the color.