views:

965

answers:

4

Hi,

A snippet from my Java application:

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

So what it does is make it self fullscreen. Now the odd thing is that the program is fullscreen but only on one monitor! E.g. I have a windows vista system with two screens that are combined in one desktop. What to do automatically let it go fullscreen over all monitors?


Ok I tried that:

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

but it gives:

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

E.g I would expect a device capable of 2048x768 as they are combined in one (I clicked on "extend desktop").

+1  A: 

That is the normal behavior when you maximize a window in Windows when you have two monitors. In order two get the full resolution size, you will need to look at GraphicsConfiguration to check each GraphicsDevice.

unholysampler
+1  A: 

You could try:

int width = 0;
int height = 0;

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

Ash
I agree. Normal behaviour is maximizing/fullscreen in one monitor. If you have an extended desktop monitor can cover only "partial" rectangles inside the big desktop rectangle. Even they could not cover all the desktop area (two monitors in diagonal by example) so you have to find the big desktop rectangle and set the size manually.
helios
+1  A: 

This is not what "setFullScreenWindow" is for. It's really for applications that want more direct access to the framebuffer (better performance) - like a 3D game does in DirectX, for instance. This kind of implies ONE monitor.

See this other answer I did: http://stackoverflow.com/questions/1722922/jdialog-not-displaying-when-in-fullscreen-mode/1723425#1723425

M1EK
A: 

Using java.awt.Toolkit you can get the full screen size (all monitors):

    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension dim = tk.getScreenSize();
Carles Barrobés