I've been successful in making java windows transparent, but I'm having trouble superimposing opaque components on top of those windows. JFrame.setOpacity(0) and AWTUtilities setWindowOpacity all transfer transparency to constituent components. In addition, JFrame.setBackground(0,0,0,0) somehow bleeds transparency to said components.
How can I fix this?
test classes: transparent background, setOpacity, and AWTUtility, respectively
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Color;
public class test {
public static void main(String[] args){
JFrame frame = new JFrame("test");
JLabel label = new JLabel("Label text");
frame.setUndecorated(true);
frame.setBackground(new Color(0,0,0,128));
frame.add(label);
frame.pack();
frame.setVisible(true);
}
}
public class test2 {
public static void main(String[] args){
JFrame frame = new JFrame("test");
JLabel label = new JLabel("Label text");
frame.setUndecorated(true);
frame.setOpacity(.50f);
frame.add(label);
frame.pack();
frame.setVisible(true);
}
}
import com.sun.awt.AWTUtilities;
import java.lang.reflect.Method;
import java.awt.Window;
public class test3 {
public static void main(String[] args){
JFrame frame = new JFrame("test");
JLabel label = new JLabel("Label text");
frame.setUndecorated(true);
try {
Class<?> awtUtilitiesClass = Class.forName("com.sun.awt.AWTUtilities");
Method mSetWindowOpacity = awtUtilitiesClass.getMethod("setWindowOpacity", Window.class, float.class);
mSetWindowOpacity.invoke(null, frame, Float.valueOf(0.50f));
} catch (Exception x){}
frame.add(label);
frame.pack();
frame.setVisible(true);
}
}
EDIT: I've tried setBackground(0,0,0,0) on Windows, where it works, but it doesn't work properly on Linux (xfce).