ShockwaveNN
ShockwaveNN

Reputation: 2268

Output jFrame to second monitor if possible

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?

Upvotes: 4

Views: 2787

Answers (1)

crusam
crusam

Reputation: 6178

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

Upvotes: 2

Related Questions