java & fullscreen over multiple monitors

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

A snippet from my Java application:

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


        
4条回答
  •  借酒劲吻你
    2020-12-14 12:14

    You could try:

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

    This should calculate the total width of multiple screens. Obviously it only supports horizontally aligned screens in the form above - you'd have to analyse the bounds of the graphics configurations to handle other monitor alignments (depends how bulletproof you want to make it).

    Edit: And then set the size of your frame: f.setSize(width, height);

提交回复
热议问题