Reputation:
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?
Upvotes: 2
Views: 1272
Reputation: 841
On Windows 10/Java 8 the ratio of text scaling factors
goes into coordinates of secondary screens.
E.g. Two screens, widths 1920 + 1600 with common border line, both text scaling 125%
Bounds java.awt.Rectangle[x=0,y=0,width=1920,height=1080]
Bounds java.awt.Rectangle[x=1920,y=174,width=1600,height=900]
Now, when the text scaling of the second screen is changed to 100%, I get
Bounds java.awt.Rectangle[x=0,y=0,width=1920,height=1080]
Bounds java.awt.Rectangle[x=2400,y=218,width=2000,height=1125]
.
The bounds of the second screen appear scaled by 125%. This is to be considered, e.g. when capturing all screens, which independent from text scaling will produce a section
Bounds java.awt.Rectangle[x=1920,y=174,width=1600,height=900]
for the secondary screen.
GraphicDevice.getDisplayMode().getWidth()
delivers the text-scale-invariant value 1600 for the second screen and so the correcting factor for the rectangles reported by GraphicsConfiguration.getBounds()
Upvotes: 0
Reputation: 33068
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
Upvotes: 2