我在Java上有一个关于Swing的jFrame,如果这个监视器存在,我希望它输出到第二个监视器。
我尝试了这个(通过this页面)来获得显示的分辨率
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
我做错了什么?
答案 0 :(得分:2)
尝试以下方法:
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() );
}
}