When I use a JLabel with a foreground color which has an alpha value, like so:
JLabel label = new JLabel( "This is non HTML text with correct alpha color" );
label.setForeground( new Color( 1.0f, 1.0f, 1.0f, 0.5f) );
the label is displayed correctly with 0.5-alpha, so 50% gray.
But when I change the text to HTML (to have more control over the text rendering), like so:
JLabel label = new JLabel( "<html><p>This is HTML text with incorrect alpha color</p></html>" );
label.setForeground( new Color( 1.0f, 1.0f, 1.0f, 0.5f) );
Then the label is 100% white. It seems, while rendering HTML, the alpha value of the foreground color is just being ignored.
I’m using Java 1.6.0_26 (32bit) under Windows 7 64 Bit.
Is this a bug or a known limitation, or do I anything wrong here?
You cannot mix HTML code and setForeground styling together.
See JLabel html text ignores setFont and How to use JLabels(1) tutorial from oracle.
Just use either HTML or JLabel styling.