matt
August 13, 2007, 11:12pm
1
TopLevelWindow::centreAroundComponent does not seem to work correctly with multiple monitors.
I am creating a dialog window that pops up over my main application window; it only seems to work correctly on the main monitor.
Unless I’m missing something, the following code seem to fix it. This is just before the end of TopLevelWindow::centreAroundComponent:
[code] const Rectangle screenArea (getParentMonitorArea());
setBounds (jlimit (screenArea.getX(), screenArea.getX() + screenArea.getWidth() - width, x),
jlimit (screenArea.getY(), screenArea.getY() + screenArea.getHeight() - height, y),
width, height);[/code]
In case it’s not obvious, I’ve changed the second parameter for each of the jlimit calls.
jules
August 14, 2007, 9:08am
2
Ah, thanks Matt - yes, I think you’re right there. Ta!
jules
August 14, 2007, 9:10am
3
Though I think what I meant to do was this:
setBounds (jlimit (screenArea.getX(), jmax (screenArea.getX(), screenArea.getRight() - width), x),
jlimit (screenArea.getY(), jmax (screenArea.getY(), screenArea.getBottom() - height), y),
width, height);
matt
September 5, 2007, 11:52pm
4
That works nicely.
One other suggestion- the line just above that reads:
I think it should be:
since “c” is the component that you’re trying to center around.
Sorry, I meant “centre”. : )
Doing this means that AlertWindows and so forth now pop up over your application for multi-monitor systems, rather than always being on the 1st monitor.
Matt
jules
September 6, 2007, 8:29am
5
I checked in a completely re-written version when you first posted this, so maybe have a look at that.
matt
September 6, 2007, 8:47pm
6
I got the latest from the trunk and it’s still not quite right; components on the second monitor are not centered properly.
The problem still seems to be in the setBounds call - I believe that the fix you posted earlier in this thread is correct.