残念ながら、2 つの画面では機能しない透明な 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;
}
}
誰もそれを修正する方法を知っていますか?
環境: Ubuntu 14.04、Cinnamon、Java 1.8.0_74-b02