Reputation: 363
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:
Thank you very much
klib
Upvotes: 3
Views: 530
Reputation: 363
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.
Upvotes: 3
Reputation: 347204
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
Upvotes: 2