我创建了透明的JDialog,不幸的是它不能在两个屏幕上工作。当它被拖到其他屏幕上时,它会变得不透明。代码如下,只需运行它并将label拖到其他屏幕上。
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
发布于 2016-03-21 23:20:28
发布于 2016-03-21 23:22:34
尽管这可能是问题的根源,也可能不是问题的根源,但最好是移除透明窗口的阴影。如果没有这些行,我的程序(在Mac上)会在中断时将阴影“烧”到窗口显示中。虽然是单显示器设置( MacBook屏幕),但在桌面之间切换会将阴影“烧焦”到窗口显示中。
JRootPane root = frame.getRootPane(); root.putClientProperty("Window.shadow", Boolean.FALSE);
https://stackoverflow.com/questions/36130906
复制相似问题