Possible bug with TopLevelWindow::centreAroundComponent


#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.


#2

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


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


#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


#5

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


#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.


#7