【问题标题】:java & fullscreen over multiple monitors多台显示器上的java和全屏
【发布时间】:2010-12-28 12:53:18
【问题描述】:

来自我的 Java 应用程序的 sn-p:

 JFrame f = new JFrame();
 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 GraphicsDevice gd = ge.getDefaultScreenDevice();
 gd.setFullScreenWindow(f);

所以它所做的就是让它自己全屏。现在奇怪的是程序是全屏的,但只在一台显示器上! 例如。我有一个带有两个屏幕的 windows vista 系统,它们组合在一个桌面上。 如何自动让它在所有显示器上全屏显示?


好的,我试过了:

import java.awt.image.ColorModel;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;

class grdevs
{
    public static void main(String [] args)
    {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] gs = ge.getScreenDevices();
        for(GraphicsDevice curGs : gs)
        {
            GraphicsConfiguration[] gc = curGs.getConfigurations();
            for(GraphicsConfiguration curGc : gc)
            {
                Rectangle bounds = curGc.getBounds();
                ColorModel cm = curGc.getColorModel();

                System.out.println("" + bounds.getX() + "," + bounds.getY() + " " + bounds.getWidth() + "x" + bounds.getHeight() + " " + cm);
            }
        } 
    }
}

但它给出了:

0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0

例如,我希望设备能够支持 2048x768,因为它们组合在一起(我点击了“扩展桌面”)。

【问题讨论】:

    标签: java swing fullscreen


    【解决方案1】:

    当您有两个显示器时,在 Windows 中最大化一个窗口时,这是正常的行为。为了让两个获得完整的分辨率大小,您需要查看 GraphicsConfiguration 以检查每个 GraphicsDevice。

    【讨论】:

      【解决方案2】:

      你可以试试:

      int width = 0;
      int height = 0;
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice[] gs = ge.getScreenDevices();
      for (GraphicsDevice curGs : gs)
      {
        DisplayMode mode = curGs.getDisplayMode();
        width += mode.getWidth();
        height = mode.getHeight();
      }
      

      这应该计算多个屏幕的总宽度。显然它只支持上面表格中的水平对齐屏幕 - 您必须分析图形配置的边界以处理其他显示器对齐方式(取决于您想要使其防弹的程度)。

      编辑:然后设置框架的大小:f.setSize(width, height);

      【讨论】:

      • 我同意。正常行为是在一台显示器中最大化/全屏显示。如果您有一个扩展的桌面监视器,则只能覆盖大桌面矩形内的“部分”矩形。即使它们无法覆盖所有桌面区域(例如对角线的两个显示器),所以您必须找到大的桌面矩形并手动设置大小。
      【解决方案3】:

      这不是“setFullScreenWindow”的用途。它确实适用于需要更直接访问帧缓冲区(更好的性能)的应用程序 - 例如,像 DirectX 中的 3D 游戏一样。这种暗示 ONE 显示器。

      查看我所做的另一个答案:JDialog Not Displaying When in Fullscreen Mode

      【讨论】:

        【解决方案4】:

        Ash 的代码更通用的解决方案是合并所有图形配置的边界

        Rectangle2D result = new Rectangle2D.Double();
        GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment();
        for (GraphicsDevice gd : localGE.getScreenDevices()) {
          for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) {
            result.union(result, graphicsConfiguration.getBounds(), result);
          }
        }
        f.setSize(result.getWidth(), result.getHeight());
        

        这适用于垂直对齐的显示器以及水平显示器。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-06-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多