Java swing center JDialog over parent

Posted by Chris Drappier on Stack Overflow See other posts from Stack Overflow or by Chris Drappier
Published on 2012-04-05T14:53:36Z Indexed on 2012/10/19 5:02 UTC
Read the original article Hit count: 125

Filed under:
|
|

I have a Java swing application with a button that produces a popup window when a certain action is performed. I'd like to align the center point of the popup window with the center point of the parent window when it is rendered. How can I calculate the x,y coordinates to plug into setLocation() for the popup window?

EDIT:

just to clarify. I do not want the behavior of setLocationRelativeTo() because that sets the top-left pixel of the popup over the center pixel of the parent frame. I want to set the center pixel of the popup over the center pixel of the parent frame. Also, I'm not interested in whether or not a popup window is good practice. I'm past that now.

thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about gui