Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.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-如何设置我的应用程序总是在主屏幕上运行,而不是在第二个屏幕上运行?_Java_Linux_Swing_Xorg - Fatal编程技术网

Java-如何设置我的应用程序总是在主屏幕上运行,而不是在第二个屏幕上运行?

Java-如何设置我的应用程序总是在主屏幕上运行,而不是在第二个屏幕上运行?,java,linux,swing,xorg,Java,Linux,Swing,Xorg,我有两个屏幕,主笔记本电脑和第二个显示器。每当我启动这个应用程序时,它都会在我的第二个屏幕而不是主屏幕上运行 我如何告诉应用程序只在主屏幕上运行,主屏幕是左边的 例如: screen = Toolkit.getDefaultToolkit().getScreenSize(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] screenDevices = ge

我有两个屏幕,主笔记本电脑和第二个显示器。每当我启动这个应用程序时,它都会在我的第二个屏幕而不是主屏幕上运行

我如何告诉应用程序只在主屏幕上运行,主屏幕是左边的

例如:

screen = Toolkit.getDefaultToolkit().getScreenSize();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screenDevices = ge.getScreenDevices();
for (int i = 0; i < screenDevices.length; i++) {
  System.out.println(screenDevices[i].getIDstring());
  DisplayMode dm = screenDevices[i].getDisplayMode();
  int screenWidth = dm.getWidth();
  int screenHeight = dm.getHeight();
  System.out.println("[myResolution]: " + screenWidth + " " + screenHeight);
  screen.width = screenWidth;
  screen.height = screenHeight;
}

Output:
0.0
1024x768
0.1
1024x768
screen=Toolkit.getDefaultToolkit().getScreenSize();
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevices[]screenDevices=ge.getScreenDevices();
对于(int i=0;i
JFrame.setLocation()难道不起作用吗? 如果您对屏幕非常挑剔,可以指定JFrame的显示位置:

第一段举了一个例子,说明如何实现你的目标