JDK-4074958 : Toolkit.getScreenResolution() doesn't return right resolution on Win95.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.1,1.1.5
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-08-28
  • Updated: 2000-09-15
  • Resolved: 2000-09-15
Related Reports
Relates :  
Description

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 ?

======================================================================
daniel.indrigo@Canada 1998-01-15


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: " +
  Toolkit.getDefaultToolkit().getScreenResolution() );

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().

Comments
WORK AROUND Name: tb29552 Date: 08/27/97 ======================================================================
11-06-2004

EVALUATION The native win32 peer code uses ::GetDeviceCaps(hDC, LOGPIXELSX) - Number of pixels per logical inch along the screen width. In a system with multiple display monitors, this value is the same for all monitors. Not a bug richard.ray@eng 2000-09-14
14-09-2000