Possible bug with TopLevelWindow::centreAroundComponent

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.

Ah, thanks Matt - yes, I think you’re right there. Ta!

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);

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.


I checked in a completely re-written version when you first posted this, so maybe have a look at that.

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.