Is there a way to set a dialog location relative to a JFrame?
I would like to center the dialog to the frame that houses my GUI, instead the dialog often appears in the center of the screen rather than within the GUI.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can:
JFrameas argument for JDialog.setLocationRelativeTo(Component c)PointfromJFrameto JDialog.setLocation(Point p)EDIT
all Swing code must be done on EventDispatchThread, meaning that
setVisible(true)should be wrapped intoinvokeLaterEDIT2
not possible, some small mistake