我创建了透明的 JDialog,不幸的是它不适用于两个屏幕。当它被拖到其他屏幕时,它变得不透明。代码如下,只需运行它并将标签拖到其他屏幕。
public class TransparentFrame{
public static void main(String[] args) {
JDialog dialog = createDialog();
SwingUtilities.invokeLater(() -> dialog.setVisible(true));
}
private static JDialog createDialog() {
JDialog dialog = new JDialog();
JLabel label = new JLabel("drag me to the other screen");
label.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
SwingUtilities.invokeLater(() -> dialog.setLocation(e.getLocationOnScreen()));
}
});
label.setOpaque(false);
dialog.getContentPane().add(label);
dialog.setUndecorated(true);
dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
dialog.setBackground(new Color(0, 0, 0, 0));
dialog.getContentPane().setBackground(new Color(0, 0, 0, 0));
dialog.pack();
return dialog;
}
}
有人知道如何解决吗?
环境:带有 Cinnamon 的 Ubuntu 14.04,java 1.8.0_74-b02