【问题标题】:moving glass pane between frames在框架之间移动玻璃板
【发布时间】:2011-04-04 06:50:41
【问题描述】:

我正在将组件从主监视器中的一帧拖到辅助监视器中的另一帧,当我将它拖到玻璃窗格中的组件时,我可以在主监视器上看到玻璃窗格,但是在鼠标到达辅助显示器,玻璃板消失了?任何人都可以帮助我吗?如何在辅助显示器上绘制玻璃板?

这是我的一些代码:

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

}

【问题讨论】:

    标签: java swing drag-and-drop glasspane


    【解决方案1】:

    但是,您在第一帧的玻璃窗格中绘制组件,您也需要对第二帧进行绘制。这听起来不是两台显示器的问题,而是两帧的问题。

    【讨论】:

    • 我构建类扩展 jpanel 并通过它绘制 glasspane 内容,所以我使用相同的类为两个框架设置 glasspane,所以使用相同的 paintComponent 函数在 glasspane 内绘制图像,但是它出现在主帧上而不是第二帧上,它与图形对象有关吗?第二个框架也是 Jdialog,我向它的所有者 Jframe 签名
    • 听起来有些奇怪,我建议创建一个 SSCCE。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多