tags:

views:

26

answers:

1

It seems that the .getBounds() method of the GraphicsConfiguration class is not reporting the correct values.

   GraphicsDevice[] gdArr = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

        int width = 0;
        for (GraphicsDevice gd : gdArr)
        {
            if (gd.getType() == gd.TYPE_RASTER_SCREEN)                                                
                System.out.println("Value is: " + gd.getDefaultConfiguration().getBounds().getX());                
        }            

I have two monitors: running 1920 * 1080 and 1280 * 1080.

I get the following values:

for .getX() I get:

Value = 1920
Value = 0

for .getY() I get:

Value = 0
Value = 0

I'm running on a Linux platform with Nvidia's Twinview. Is this a bug outside of Swing?

+3  A: 

This is not a bug. The values are correct.

You are getting the bounds of each screen, and then you are getting the X and Y coordinates of each bound, which is the coordinate of the upper-left corner. GraphicsConfiguration.getBounds() returns a Rectangle defining the screen boundaries. Rectangle.getX() and Rectangle.getY() return the coordinates of the upper-left corner of the rectangle. Rectangle.getWidth() and Rectangle.getHeight() return the size.

You have two monitors. Here are the boundaries of each monitor:

1: X = 0   , Y = 0, Width = 1920, Height = 1080
2: X = 1920, Y = 0, Width = 1280, Height = 1080
Erick Robertson
+1. Rectangle implements toString, so try just `System.out.println(...getBounds());` to see the whole deal.
Mark Peters
Thansk guys! That was it!
Carlo del Mundo