ama
ama

Reputation: 369

moving glass pane between frames

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

}

Upvotes: 0

Views: 323

Answers (1)

jzd
jzd

Reputation: 23629

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.

Upvotes: 2

Related Questions