在框架之间移动玻璃板

发布于 2024-10-29 02:02:51 字数 1555 浏览 0 评论 0原文

我将组件从主显示器中的一个框架拖动到辅助显示器中的另一个框架,当我拖动玻璃板中绘制的组件时,我可以看到主显示器上的玻璃板,但在鼠标到达辅助显示器后,玻璃板消失了?任何人都可以帮助我吗?如何在辅助显示器上绘制玻璃板?

这是我的一些代码:

public class Main_Frame extends JFrame

{

     public Main_Frame (){
        //adding  the content of main JFrame
        setGlassPane(new  ImageGlassPane());
        //detect other screens and making object of Second_Frame for each
     }
}

public class Second_Frame extends JDialog{
    public Second_Frame(){
       super(new Frame(MultiMonitor.getInstance().getNextDevice().getDefaultConfiguration()), 
          Title, false);
       setGlassPane(new  ImageGlassPane());
    }

}

    public class ImageGlassPane() extends JPanel{
public ImageGlassPane() {
           setOpaque(false);

     }

     protected void paintComponent(Graphics g) {
        if ( !isVisible()) {
            return;
        }
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);

        int x = (int) (location.getX() - (width * zoom / 2));
        int y = (int) (location.getY() - (height * zoom / 2));

        if (visibleRect != null) {
            g2.setClip(visibleRect);
        }

        if (visibleRect != null) {
            Area clip = new Area(visibleRect);
            g2.setClip(clip);
        }

        g2.drawImage(image, x, y, (int) (width * zoom), (int) (height * zoom), null);
    }

}

I'm dragging component from one frame in main monitor to another frame in secondary monitor ,and while I'm dragging it the component painted in glasspane, I can see the glasspane over the main mointor ,but after the mouse reach the secondary monitor, the glasspane disappears? Can any one help me in this? How I can paint the glasspane over the secondary monitor?

Here is some pieces of my code:

public class Main_Frame extends JFrame

{

     public Main_Frame (){
        //adding  the content of main JFrame
        setGlassPane(new  ImageGlassPane());
        //detect other screens and making object of Second_Frame for each
     }
}

public class Second_Frame extends JDialog{
    public Second_Frame(){
       super(new Frame(MultiMonitor.getInstance().getNextDevice().getDefaultConfiguration()), 
          Title, false);
       setGlassPane(new  ImageGlassPane());
    }

}

    public class ImageGlassPane() extends JPanel{
public ImageGlassPane() {
           setOpaque(false);

     }

     protected void paintComponent(Graphics g) {
        if ( !isVisible()) {
            return;
        }
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);

        int x = (int) (location.getX() - (width * zoom / 2));
        int y = (int) (location.getY() - (height * zoom / 2));

        if (visibleRect != null) {
            g2.setClip(visibleRect);
        }

        if (visibleRect != null) {
            Area clip = new Area(visibleRect);
            g2.setClip(clip);
        }

        g2.drawImage(image, x, y, (int) (width * zoom), (int) (height * zoom), null);
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临风闻羌笛 2024-11-05 02:02:51

然而,您要在第一个框架的玻璃板上绘制组件,您也需要对第二个框架进行绘制。这听起来不是两个显示器的问题,而是两个框架的问题。

However you are painting the component in the glass pane on the first frame, you will need to do for the second frame as well. This sounds like it is not a two monitor issue, but a two frame issue instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文