Skip to main content

Mulitscreens with phantom devices

9 replies [Last post]
Joined: 2004-04-27

The problem I wanna solve is to detect if a given Dialog fits on the screen. The code itself works quite fine, but I have a strange problem, which seems to be related with mulitple monitors (=multiscreen).

I have the following code

      GraphicsEnvironment ge =<br />
        GraphicsEnvironment.getLocalGraphicsEnvironment();<br />
      GraphicsDevice[] sd = ge.getScreenDevices();</p>
<p>      for (GraphicsDevice device:sd) {<br />
        //Point of interest::::::<br />
        if (device.getDisplayMode().getRefreshRate() == 0) {<br />
          continue;<br />
        }<br />
        //perform the check<br />

I loop through the detected monitors and make my checks. But somehow I get as well a device, which is not linked to a real device.

On my laptop I have turned off laptop-screen and turned on monitor. sd.length==2. And the second device is definitely not valid, cause I have RefreshRate with 0 and no insets, but I have a valid Screenresolution from my first screen, and many interesting items.

If I turn on the laptop-screen, leave the monitor as primary monitor, I get sd.lenght==3. With the strange result, that the second has still the above mentioned values.

So, my question is, how to determine, if the sd[] does really contain valid devices? Is it a valid approach to test against the getRefreshRate()? Is there some more accurate property/method to test against?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-07-24

And btw, thanks for reporting the issue!

Joined: 2006-07-24

Laptops may have three video devices: LCD, ext. Monitor, and TV-out. Perhaps that might be the cause?

To answer your very last question, please define "valid device".

Also, have you calculated the desired size of a dialog and want to put it to the best-fit screen? Or are you determining whether an already displayed dialog fits the screen? What's your primary objective?

Joined: 2004-04-27

Uhu, I didn't think about the possiblity of the other outputs. Seems reasonable.

Under Windows I define as a "valid device" all activated screens (System properties=> Display=>Settings). Under Windows I get only the selection-option for 2 displays and not for 3. So, I wonder why windows only offers 2 and what does Java understand with the third one. And the third one is an "invalid device" in sense of, I cannot display anything on it, nor can the user (=me) read from it.

And to have the question little bit more complicated: If I have only one display activated, why then get only 2? I would have then expected to have 3, if the result returns the capability of the laptop.

Bottom line is, how to get *only* these displays which are activated under Windows? Is the RefreshRate a bullet-proof way for testing? Or is there a better way?

[Linux behaves the same way?]

And about the purpose: As you mention, 'Or are you determining whether an already displayed dialog fits the screen? ' But more in the way, if the user could see the Dialog, i.e. is shown on display and not somewhere on an invalid device or in Nirvana ;) This part I have already coded, beside the side-effect of screen-sizes of *invalid* devices ;)

Joined: 2006-07-24

Hmm... how come a Dialog goes to... Nirvana? :) And why do you want to know whether it's there or somewhere else?

I just don't quite understand the core problem you're trying to resolve.

Joined: 2004-04-27

Open a modal Dialog, set the position to (-400,-1800) and have only one monitor attached. So, the Dialog is displayed in the Nirvana unless you have enabled a second monitor with matching size. But your mainframe gets inactive and only the advanced user knows that there is some *modal* Dialog in the Nirvana displayed. ;)

But this gets me off the track, of what I wanna know and brings me to some kind of reasoning 'Why I do it this way?' and 'Why not do it the other way?' Or do I misunderstand your statement reg. 'you don't understand my core problem'? I just wanna have some kind easiness and not wanna start from the scratch elaborating why I am stuck. I come to a problem and ask for help for my particular problem if it could be solved the specific way I have chosen.

So, could I rely on the RefreshRate or not. If not, is there a better way?

Joined: 2006-07-24

The easiest solution to your problem is to NOT set the position to (-400, -1800). :) In most cases the setLocationByPlatform() or setLocationRelativeTo() should give you quite satisfying results. I suggest to set the position explicitly only after a user drags the frame to another position, and you want to save the position between application runs. So my next "philosophical" Q would be: why do you do that? :)

Now back to technical issues. The refresh rate of 0 (which actually corresponds to the constant REFRESH_RATE_UNKNOWN - and using the constant is much more preferred) isn't specified as a value allowing to determine whether the device is what you want it to be. In most cases the value of zero means that the rate just can't be retrieved from the system, however, the device may be quite "valid" in your terms.

Could you please post a print-out of all the getIDstring()'s and getType()'s for all of your GraphicsDevice's?

Joined: 2004-04-27

"philosophical" Q: I guess, this would end in some kind of flame. Sorry, I do not wanna spend my energy in this ;)

About the technical issues:

[code] GraphicsEnvironment ge =
GraphicsDevice[] sd = ge.getScreenDevices();

for (GraphicsDevice device:sd) {
System.out.println("Device ID=" + device.getIDstring() + "; Type="
+ device.getType() + ";Bounds="
+ device.getDefaultConfiguration().getBounds()
+ "; RefreshRate="
+ device.getDisplayMode().getRefreshRate());
//Point of interest::::::
if (device.getDisplayMode().getRefreshRate() == 0) {
//perform the check

results in

Device ID=\Display0; Type=0;Bounds=java.awt.Rectangle[x=0,y=0,width=1024,height=768]; RefreshRate=60
Device ID=\Display1; Type=0;Bounds=java.awt.Rectangle[x=0,y=0,width=1200,height=1920]; RefreshRate=0
Device ID=\Display2; Type=0;Bounds=java.awt.Rectangle[x=-1024,y=-360,width=1024,height=1280]; RefreshRate=60

And interesting is, that Display1 has more or less invalid width, height. I have attached once before a monitor with the same size, but not for the moment. (And also not before starting Java!)

Joined: 2006-07-24

As you wish sir! :)

Anyways, I've filed 6988243 to track the issue. It looks like the "ghost" devices are reported by the native system, and I haven't found a way to distinguish between real and "invalid" devices yet. So you're welcome to track the bug on the site (the bug will be visible in 24 h).

Joined: 2004-04-27

> As you wish sir! :)

Good, that there is still some fun in it :) Is THIS the reason, why I like coding? ;)

> Anyways, I've filed 6988243 to track the issue. It
> looks like the "ghost" devices are reported by the
> native system, and I haven't found a way to
> distinguish between real and "invalid" devices yet.
> So you're welcome to track the bug on the
> site (the bug will be visible in 24 h).

Thx for assitance and help on this part.