如果可能,将jFrame输出到第二个监视器 [英] Output jFrame to second monitor if possible

查看:150
本文介绍了如果可能,将jFrame输出到第二个监视器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i have a jFrame on Swing in Java, and i want it to output to second monitor, if this monitor exists.

我试过这个(通过页面)以获取显示分辨率

I tried this (by this page) to get resolutions of displays

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 for
我的第一台显示器(1360 * 768)xoffs = 1360和yoffs = 0
秒显示器(1280 * 1024)xoffs = 0和yoffs = 0

But then i watch in debugger to xoffs and yoffs for my first monitor (1360*768) xoffs = 1360 and yoffs = 0 second monitor (1280*1024) xoffs = 0 and 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() );
   }
}

这篇关于如果可能,将jFrame输出到第二个监视器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆