如果可能,将jFrame输出到第二个监视器

我有一个关于Java的Swing的jFrame,如果这个监视器存在,我希望它输出到第二个监视器。

我尝试了这个(通过这个页面)来获得显示的分辨率

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { GraphicsConfiguration[] gc = gs[j].getConfigurations(); for (int i = 0; i < gc.length; i++) { Rectangle gcBounds = gc[i].getBounds(); int xoffs = gcBounds.x; int yoffs = gcBounds.y; } } 

但后来我在调试器中看到xoffs和yoffs为我的第一台显示器(1360 * 768)xoffs = 1360和yoffs = 0秒显示器(1280 * 1024)xoffs = 0和yoffs = 0

我究竟做错了什么?

请尝试以下方法:

 public static void main( String[] args ) { java.awt.GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); for ( int i = 0; i < devices.length; i++ ) { System.out.println( "Device " + i + " width: " + devices[ i ].getDisplayMode().getWidth() ); System.out.println( "Device " + i + " height: " + devices[ i ].getDisplayMode().getHeight() ); } }