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

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

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

例:

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 

没有JFrame.setLocation()工作? 如果您对屏幕非常挑剔,那么您可以指定显示JFrame的位置: http : //docs.oracle.com/javase/6/docs/api/java/awt/GraphicsDevice.html

第一个段落举例说明如何实现你想要的