0

I am writing a plugin for intellij. I am launching a JDialog when a menu item is clicked. The problem is that the JDialog opens at the top left corner of screen. I tried using setLocationRelativeTo(null) but it placed the dialog at the center of the first screen while the intellij IDE was open on some other screen.

An answer here says how to use GraphicsEnvironment api to position a Window in a particular screen, but then how do I specify which screen the intellij IDE is launched in.

Community
  • 1
  • 1
amit
  • 21
  • 1
  • 3
  • Do you have reference of the parent `Window/JFrame` in your plugin development environment? – STaefi Sep 07 '15 at 05:38
  • Yes, parent window was required and I found suggestParentWindow function in the WindowManager.java which returns a parent window. I just searched for this randomly and I am not sure if there exists any other way to get the root Window in intellij idea that I can use as a parent window. This works for me. – amit Sep 08 '15 at 20:52

1 Answers1

0

If you somehow can get the parent Window/Frame reference you can find out in which GraphicDevice the Intellij is being rendered:

JWindow parentWindow = ... // reference to your plugin parent window
GraphicsConfiguration cfg = myWindow.getGraphicsConfiguration();
GraphicsDevice intellijScr = cfg .getDevice();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] allDevices = ge.getScreenDevices();
int intellijScrIndex = -1;
for (int i = 0; i < allDevices.length; i++) 
{
    if (allDevices[i].equals(intellijScr))
    {
        myScreenIndex = i;
        break;
    }
}

From now on, I think you are good to go with the solution you've found before.

Good Luck.

Community
  • 1
  • 1
STaefi
  • 4,297
  • 1
  • 25
  • 43