I have a strange behaviour with a legacy application I have to maintain. On startup, the JFrame of the application is moved to the position where it has been closed recently (which works fine, even on multi monitor settings).
When the JFrame is moved to a secondary monitor (done by calling setLocation(x, y)) and a JDialog is shown after calling setRelativeTo(mainFrame), the JDialog appears on the primary monitor.

One has to drag the mainframe on the primary monitor and back to the secondary one to avoid the problem.

I have found, that calling mainFrame.getGraphicsConfiguration().getDevice().getIDstring() returns \Display0 when the application is started (means 'Primary Display' afaik), even though it is shown on the secondary monitor. When I drag the main frame to the primary monitor and back to the secondary one, the Method returns \Display1.

Now I have 2 questions:

  1. Is there a way to tell the application on which monitor it is positioned?
  2. I have tried to create a simple example with JFrame and a JDialog. Unfortunately it behaves as expected and I can't reproduce the problem. Do you have a hint on what to look for in my application, that could cause this behaviour?

Thank you very much
klib

有帮助吗?

解决方案

After some more research I found that I had to call mainframe.setVisible(false);and again mainframe.setvisible(true);.
This is sufficient that mainframe.getGuiConfiguration.getDevice() returned the right device-ID.

I know, this is not really a solution to the original problem, but it might help if someone else experiences the same behaviour.

Anyway, Explanations / real solutions for the problem are still very appreciated.

其他提示

For your first question, you could use JFrame(GraphicsConfiguration).

If the problem isn't repeatable, there might be something else going on that is messing things up

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top