拖动到第二个屏幕时,透明的JDialog变得不透明(带有Cinnamon,Java 1.8.0_74-b02的ubuntu 14.04) [英] transparent JDialog becomes opaque when dragging to second screen (ubuntu 14.04 with Cinnamon, java 1.8.0_74-b02)

查看:51
本文介绍了拖动到第二个屏幕时,透明的JDialog变得不透明(带有Cinnamon,Java 1.8.0_74-b02的ubuntu 14.04)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了透明的JDialog,不幸的是,它无法在两个屏幕上运行.当将其拖动到其他屏幕时,它变得不透明.代码在下面,只需运行它并将标签拖到其他屏幕即可.

I created transparent JDialog which unfortunately does not work with two screens. When its dragged to other screen it becomes opaque. The code is below, just run it and drag label to other screen.

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;
}

}

有人知道如何解决吗?

环境:具有肉桂,Java 1.8.0_74-b02的Ubuntu 14.04

Environment: Ubuntu 14.04 with Cinnamon, java 1.8.0_74-b02

推荐答案

尽管这可能是(也可能不是)问题的根源,但最好是去除透明窗口的阴影.没有这些行,我的程序(在Mac上)将在中断时将阴影燃烧"到窗口显示中.尽管它是单个显示器设置(MacBook屏幕),但在台式机之间切换会把阴影烧入"到窗口显示中.

Although this may or may not be the source of the problem, it's best to remove the shadow of a transparent window. Without these lines, my program (on Mac) would "burn" the shadows into the window display when interrupted. Although it's a single monitor setup (the MacBook screen), switching between desktops would "burn" the shadows into the window display.

JRootPane root = frame.getRootPane(); root.putClientProperty("Window.shadow", Boolean.FALSE);

JRootPane root = frame.getRootPane(); root.putClientProperty("Window.shadow", Boolean.FALSE);

这篇关于拖动到第二个屏幕时,透明的JDialog变得不透明(带有Cinnamon,Java 1.8.0_74-b02的ubuntu 14.04)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆