Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中的双监视器配置上保持jframe打开_Java_Multiple Monitors - Fatal编程技术网

在Java中的双监视器配置上保持jframe打开

在Java中的双监视器配置上保持jframe打开,java,multiple-monitors,Java,Multiple Monitors,我有一个双监视器配置,我设法在所需屏幕上打开了我的Jframe 但问题是,每次我点击我的主屏幕,另一个窗口就会最小化,但我需要始终处于顶部 PS:我选中了“始终在顶部”复选框 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); 这就是我使用另一个屏幕的方式。只要我使用setFullScreenWindow,

我有一个双监视器配置,我设法在所需屏幕上打开了我的
Jframe

但问题是,每次我点击我的主屏幕,另一个窗口就会最小化,但我需要始终处于顶部

PS:我选中了“始终在顶部”复选框

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();

这就是我使用另一个屏幕的方式。

只要我使用setFullScreenWindow,我也会遇到同样的问题。用对话框替换框架解决了这个问题,但我想你真的想要一个框架,而不是一个对话框

因此,解决方案是手动最大化帧,而不是使用setFullScreenWindow:

import java.awt.*;
import javax.swing.*;

public class MultiMonitorFrame extends JFrame {

    public static void showFrameOnScreen(Window frame, int screen) {
        GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();
        GraphicsDevice graphicsDevice = ( screen > -1 && screen < graphicsDevices.length ) ? graphicsDevices[screen] : graphicsDevices.length > 0 ? graphicsDevices[0] : null;
        if (graphicsDevice == null)
        {
            throw new RuntimeException( "There are no screens !" );
        }
        Rectangle bounds = graphicsDevice.getDefaultConfiguration().getBounds();
        frame.setSize(bounds.width, bounds.height);
        frame.setLocation(bounds.x, bounds.y);
    }

    public static void main(String[] args) {
        JFrame frame1 = new JFrame("First frame");
        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame1.setVisible(true);
        frame1.setAlwaysOnTop(true);
        JFrame frame2 = new JFrame("Second frame");
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame2.setVisible(true);
        frame2.setAlwaysOnTop(true);
        showFrameOnScreen(frame1, 1);
        showFrameOnScreen(frame2, 2);
    }
}
import java.awt.*;
导入javax.swing.*;
公共类MultiMonitorFrame扩展了JFrame{
屏幕上的公共静态void showFrameOn(窗口框架,内部屏幕){
GraphicsEnvironment GraphicsEnvironment=GraphicsEnvironment.getLocalGraphicsEnvironment();
graphicsDevices[]graphicsDevices=graphicsEnvironment.getScreenDevices();
graphicsDevices graphicsDevices=(屏幕>-1&&screen0?graphicsDevices[0]:空;
如果(graphicsDevice==null)
{
抛出新的RuntimeException(“没有屏幕!”);
}
矩形边界=graphicsDevice.getDefaultConfiguration().getBounds();
frame.setSize(bounds.width、bounds.height);
frame.setLocation(bounds.x,bounds.y);
}
公共静态void main(字符串[]args){
JFrame frame1=新JFrame(“第一帧”);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setVisible(true);
frame1.setAlwaysOnTop(正确);
JFrame frame2=新JFrame(“第二帧”);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.setVisible(true);
frame2.setAlwaysOnTop(正确);
屏幕上显示框架(框架1,1);
屏幕上显示框架(框架2、2);
}
}

这显示了一台显示器上的两个帧,当使用ALT选项卡或单击桌面时,这些帧不会最小化。

您使用哪种操作系统?每次我点击我的主屏幕,你的意思就是点击一个非常随机的位置吗?我使用的是windows 10和windows 7。我的意思是,单击与Jframe不同的任何地方都会使窗口最小化。我需要单击一个屏幕上的一些按钮,然后查看另一个屏幕上的修改。