Hi.
After a lot of struggling I have finally code of per pixel transparency which works: JFrame with translucent gradient background + 1 opaque button. BUT! I works only (among other tested OS/JDK) in JDK7 and windows 7. Alpha channel is totally missing with windows 10, XFCE, both using JDK8.
So the question is:
is this feature actually working and I'm just missing some magical switches in windows / xfce? Or it's rather considered as unstable feature?
Note: code in question is just a prototype, what I'm really after is ability "to see through some glass" and being able to paint on it, regardless what applications (not just mine, therefore no glasspane) are running below. If there is nice solution I can use instead you can recommend, please do! (note2: screenshotting using robot could be considered as plan-b, but really insufficient one, as it disallows to see changes below "glass").
Thanks!
EDIT, the code(I stole it somewhere and did some minor fixing changes. But again on windows7 JDK7 it works perfectly.):
import static java.awt.GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Trans3 extends JFrame { public Trans3() { super("GradientTranslucentWindow"); setUndecorated(true); setBackground(new Color(0, 0, 0, 0)); setSize(new Dimension(300, 200)); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel panel = new JPanel() { @Override protected void paintComponent(Graphics g) { if (g instanceof Graphics2D) { final int R = 240; final int G = 240; final int B = 240; Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0), 0.0f, getHeight(), new Color(R, G, B, 255), true); Graphics2D g2d = (Graphics2D) g; g2d.setPaint(p); g2d.fillRect(0, 0, getWidth(), getHeight()); } } }; setContentPane(panel); setLayout(new GridBagLayout()); JButton button = new JButton("exit"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); dispose(); } }); add(button); } public static void main(String[] args) { // Determine what the GraphicsDevice can support. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); boolean isPerPixelTranslucencySupported = gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT); //If translucent windows aren't supported, exit. if (!isPerPixelTranslucencySupported) { System.out.println("Per-pixel translucency is not supported"); System.exit(0); } JFrame.setDefaultLookAndFeelDecorated(false); // Create the GUI on the event-dispatching thread SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Trans3 gtw = new Trans3(); // Display the window. gtw.setVisible(true); } }); } }