【问题标题】:Output jFrame to second monitor if possible如果可能,将 jFrame 输出到第二个监视器
【发布时间】:2011-07-19 14:23:02
【问题描述】:

我在 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

我做错了什么?

【问题讨论】:

  • 在那个问题中,他们使用方法 setFullScreenWindow( frame ) 来设置 jFrame 全尺寸,但我不想让它全尺寸框架。但现在我想在第一台显示器上获取尺寸,并按此数字移动以在第二台显示器上显示表格

标签: java swing jframe multiple-monitors


【解决方案1】:

尝试以下方法:

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() );
   }
}

【讨论】:

  • 不同意是否有多个 GPU,顺便说一句 +1
  • 谢谢,它的工作,它输出正确的分辨率。而且我没有带多个 GPU 的 PC,所以它对我来说工作正常
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-28
  • 2016-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-27
相关资源
最近更新 更多