4

i have a jFrame on Swing in Java, and i want it to output to second monitor, if this monitor exists.

I tried this (by this page) to get resolutions of displays

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

But then i watch in debugger to xoffs and yoffs for my first monitor (1360*768) xoffs = 1360 and yoffs = 0 second monitor (1280*1024) xoffs = 0 and yoffs = 0

What am i doing wrong?

ShockwaveNN
  • 2,227
  • 2
  • 29
  • 56
  • 2
    Possible duplicate - http://stackoverflow.com/questions/4627553/java-show-jframe-in-a-specific-screen-in-dual-monitor-configuration – Moonbeam Jul 19 '11 at 14:25
  • 1
    In that question they use method setFullScreenWindow( frame ) to set jFrame full size, but i don't want to make it full size frame. But now i want to get dimensions on first monitor, and shift by this numbers to display form on second monitor – ShockwaveNN Jul 19 '11 at 14:29

1 Answers1

2

Try the following:

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() );
   }
}
crusam
  • 6,140
  • 6
  • 40
  • 68