【问题标题】:Launching a JDialog at the center of screen in a multi screen environment in an intellij plugin在 intellij 插件的多屏幕环境中在屏幕中心启动 JDialog
【发布时间】:2015-12-01 04:26:39
【问题描述】:

我正在为 intellij 编写一个插件。单击菜单项时,我正在启动 JDialog。问题是 JDialog 在屏幕的左上角打开。我尝试使用 setLocationRelativeTo(null) 但它将对话框放置在第一个屏幕的中心,而 intellij IDE 在其他屏幕上打开。

答案here 说如何使用 GraphicsEnvironment api 将 Window 定位在特定屏幕中,但是我如何指定 intellij IDE 在哪个屏幕中启动。

【问题讨论】:

  • 你的插件开发环境中有父Window/JFrame的引用吗?
  • 是的,父窗口是必需的,我在 WindowManager.java 中找到了返回父窗口的SuggestParentWindow 函数。我只是随机搜索了这个,我不确定是否存在任何其他方法可以在 intellij 想法中获取根窗口,我可以将其用作父窗口。这对我有用。

标签: java swing intellij-idea


【解决方案1】:

如果您能以某种方式获得父 Window/Frame 引用,您可以找出 Intellij 在哪个 GraphicDevice 中呈现:

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;
    }
}

从现在开始,我认为你可以使用之前找到的solution

祝你好运。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多