3

I need to detect which display is used for running a Java application. Possible options are:

  • Desktop with monitor
  • Laptop with monitor
  • Laptop with internal display

The application's behaviour depends on the display type: For the first two options (both monitor) it's same, for the third option the behaviour is different.

At first I used the screen resolution to detect the display type as the valid settings are known and limited (height >1000px: monitor); however, now I have to handle laptops with the same internal screen resolution as the monitor.

The application only runs on Windows XP and Windows 7 which might make it easier; however, I didn't find any solution yet. Do you know of any way to resolve this problem? Best would be with Java only of course, but if that's not possible any other way that can be used from a Java application will help. The only limitation is that I can't install new software and when using external libraries I'm limited to those which are free for commercial use.

This question was marked as a duplicate of another question regarding screen detection but isn't. So just to clarify again: This question is NOT about using several displays at the same time. This question is just about using one display and detecting what kind of display it is (which might work by knowing the dpi or alternatively some identifier that tells me whether it's an integrated or external display - but to my knowledge non of them is available (dpi is available but only from a system setting that defaults to 96 and is unreliable)).

Pizzamampf
  • 31
  • 2
  • Just out of interest: why would the behavior be different between a monitor and an internal display? – Thomas Apr 02 '14 at 13:25
  • have you checked http://stackoverflow.com/a/2234640/1007273 – hovanessyan Apr 02 '14 at 13:35
  • It's necessary for ergonomic reasons: The user can set different font sizes (and some other options) for monitor and laptop display. Once the user switches from laptop display to monitor, the font size changes according to his preferred settings. – Pizzamampf Apr 02 '14 at 13:38
  • @hovanessyan: That's for detecting which display contains the application. However, if you use laptop with internal display you have the device "\Display0" and if you use the laptop with monitor it's the same. Unfortunately that doesn't help in this case (I already tried hoping a laptop with monitor attached would always have two displays even if the internal one is switched off). – Pizzamampf Apr 02 '14 at 13:42
  • @Pizzamampf: Can't you make your application set a "property" (on runtime ... to "desktop" or "notebook") , and evaluate the (current window) device id regarding this property? – xerx593 Apr 27 '15 at 21:34
  • @xerx593 I could set a property to know what kind of machine it is. However, I still don't know of any way to detect which kind of display is used. Example: a) Notebook with 15" display, resolution of 1920x1200; b) Notebook with 24" display attached, also resolution of 1920x1200, internal display off. => In both cases I find one display ("\Display0"), both have identical resolution so I can't differ between both in my code. However, ergonomic rules say that I need to provide a certain font size - that is set as "character size in millimeters" which I can't do without knowing the display size. – Pizzamampf Apr 28 '15 at 22:12
  • ..then please look (again) at http://stackoverflow.com/a/2234640/1007273 (thx, @hovanessyan), device 0 -> "main device", device 1 -> "secondary device", ... this + the information, whether you are desktop/laptop + your window position, should give you enough information, whether you are on "internal display" or "monitor". (?) – xerx593 Apr 28 '15 at 22:16
  • @xerx593 As I already wrote, I just have "\Display 0". There is no other, no "secondary device". Either it is the notebook screen or the desktop screen, but never both are switched on and so I have no way to find the difference. – Pizzamampf Apr 29 '15 at 16:36
  • @Pizzamampf Have you read the second sentence of the target question and the top answer? – TylerH Feb 09 '17 at 20:01
  • Yes, I have. That's about having multiple displays at the same time and knowing on which of them the application is shown. Unfortunately it doesn't help at all for my problem because it's something completely different. I'm afraid the simple answer to my problem is: It's not possible. And won't be in the foreseeable future. – Pizzamampf Feb 10 '17 at 20:45

0 Answers0