I’m trying to create a translucent window with Java on OSX and add a JLabel to it.
This JLabel changes its text every second….

However the component is not repainting well.
How can I solve this problem?
I’ve found the these articles, but I can’t figure out how to solve it.
If possible, please paste the fixing source code, here’s mine:
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Font;
import java.util.Timer;
import java.util.TimerTask;
public class Translucent {
public static void main( String [] args ) {
JFrame frame = new JFrame();
frame.setBackground( new Color( 0.0f,0.0f,0.0f,0.3f));
final JLabel label = new JLabel("Hola");
label.setFont( new Font( label.getFont().getFamily(), Font.PLAIN, 46 ) );
label.setForeground( Color.white );
frame.add( label );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible( true );
Timer timer = new Timer();
timer.schedule( new TimerTask(){
int i = 0;
public void run() {
label.setText("Hola "+ i++ );
}
}, 0, 1000 );
}
}
I’ve had some luck extending
JLabeland implementingIconto get a translucent component working the way I want. You can see the result of various rule combinations in this AlphaCompositeDemo.The example below is 100% white atop 50% black.Addendum: Note how this example composites opaque text on a clear offscreen background over the translucent frame background.
Addendum: Here’s a way to make the whole frame translucent. Unfortunately, it dims the content, too.