java & fullscreen over multiple monitors

前端 未结 4 1409
春和景丽
春和景丽 2020-12-14 11:39

A snippet from my Java application:

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


        
4条回答
  •  -上瘾入骨i
    2020-12-14 12:18

    A more general solution to Ash's code is to union the bounds of all the graphics configurations

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

    This will work for vertically aligned monitors as well as horizontal.

提交回复
热议问题