I’m working on a Java application which allows users to “drill down” on items in a Dialog box. This means popping up one modal dialog on top of another — and locating them screen-center. But by the time I get to my third dialog box in, the drawing of the dialog takes forever — sometimes a couple of seconds.
The offending code seems to be the screen-centering, which I’m doing like this:
setLocationRelativeTo(null);
I comment that line out and the dialogs draw instantly. It’s also instant if I set the location like this:
setLocation(300,400);
But if I do screen-dimension math and set the location to some other values, I again get the delay.
Dimension d = getSize(); // Dialog size
// Use the above to calculate a location
setLocation(frame.screenCenter.x - (d.width / 2), frame.screenCenter.y - (d.height / 2));
Can someone explain what’s causing this behavior? And is there any way around it?