Jacob said:
// Pixel size of screen
Dimension pixelSize = Toolkit.getDefaultToolkit().getScreenSize();
// Screen resolution (for some reason returned as inches, please fix Sun!)
int pixelsPerInch = Toolkit.getDefaultToolkit().getScreenResolution();
double pixelsPerMeter = pixelsPerInch / 0.0254;
// Compute width and heigth of screen in meters
double screenWidth = pixelSize.width / pixelsPerMeter;
double screenHeight = pixelSize.height / pixelsPerMeter;
Hi Jacob,
Thank you very much for answer. I have tried that
Toolkit.getDefaultToolkit().getScreenResolution();
No matter how I set my resolution: 1024x768, 1600x1200, it always gives back
120 dpi. Then 1024/120= 8 inches, 768/120=6 inches, then the diagonal size
will be 10 inches, but actually I am using a 20 inch monitor...
so that's the problem, Java does not know how to get the actual physical
viewable size of the monitor:
I found in VC++, it has the following:
hSize=GetDeviceCaps(hScreenDC,HORZSIZE);
vSize=GetDeviceCaps(hScreenDC,VERTSIZE);
gives back the correct values in "cm",
but I really want to get the values in Java, for cross platform
compatibility...
Any more thoughts?
Thanks a lot,
-Lucy