Name: tb29552 Date: 08/27/97
company - Battelle PNNL , email - ###@###.###
On my windows 95 box, the call of
ToolKit tk = Toolkit.getDefaultToolKit();
int dpi = tk.getScreenResolution();
System.out.println("Screen Resolution in dpi is " + dpi);
always returns 120 dpi. This result is always 120 , even though
I may be running windows at 72 or 96 dpi.
I have run the program on a Sun machine and I get the correct results there,
so I suspect this may be a Win 95 bug, or may be something to do
with my hardware device drivers. Any clues ?
The Toolkit.getScreenResolution doesn't work correctly. It returns hardcoded values for the screen resolution based on the use of small or large fonts, rather than calling the GetDeviceCaps function in the Win32 API. Please fix this in the next release because it greatly complicates the ability to draw anything to scale on the display and the printer. The hardcoded values are 96 for any resolution using small fonts, and 120 for any resolution using large fonts. This means that 1600x1280 resolution (configured with small fonts) is less than 640x480 resolution (configured with large fonts). It also means that the same resolution is different when using large fonts vs small. Fonts have nothing to do with screen resolution. This issue is complicated by the fact that the point sizes used for creating fonts use the true resolution - which can't be determined.
To verify this try the following with small and large font configurations in any resolution:
System.out.println( "Resolution: " +
You can use the following code from the Win32 API to solve the problem in AWT:
dpi = GetDeviceCaps( myDC, LOGPIXELSX );
Please fix it. You are probably already using it in PrintJob.getResolution().