在框架之间移动玻璃板
我将组件从主显示器中的一个框架拖动到辅助显示器中的另一个框架,当我拖动玻璃板中绘制的组件时,我可以看到主显示器上的玻璃板,但在鼠标到达辅助显示器后,玻璃板消失了?任何人都可以帮助我吗?如何在辅助显示器上绘制玻璃板?
这是我的一些代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
然而,您要在第一个框架的玻璃板上绘制组件,您也需要对第二个框架进行绘制。这听起来不是两个显示器的问题,而是两个框架的问题。
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.