Having recently seen a couple dialog boxes in a MPS project that appeared in the top left corner of the screen rather than centered in the MPS project window, I wanted to share a simple tip on how to fix this.
All Swing dialogs have a method called
setLocationRelativeTo(Component), inherited all the way from
that does exactly this.
If you don’t have an appropriate component at hand to pass to that method, such as the editor component or another
dialog that is currently being shown on screen, you can always use the project window, also known as the IDE frame. To
get this frame you can use
Thus, the code looks like this:
Frame projectFrame = ProjectHelper.toMainFrame(mpsProject); dialog.setLocationRelativeTo(projectFrame);
And the dialog is now shown centered: