DialogWrapper.createCenterPanel() not centered
The scenario:
1) A plugin creates a dialog by implementing the class DialogWrapper and its createCenterPanel() method.
2) The plugin runs on a workstation with 2 monitors. IntellIJ is maximized on the second monitor.
The problem:
The plugin window is created on the first monitor, instead of being created at the center of the second monitor. Note that IntelliJ dialogs in general are not subject to this problem. For instance, the "Go to / class" dialog is correctly displayed at the center of the IntelliJ window, even when the IntelliJ window is on the second monitor.
A plugin that exhibits this behavior is the excellent TabSwitch plugin created by Timur, see: https://sourceforge.net/projects/tz-ip/
Is there some other API that can used by plugins to achieve this goal, or if this is a problem with the IntelliJ open API, is there any work-around?
Alex
请先登录再写评论。
createCenterPanel has nothing to do with centering the window.
it creates the BorderLayout.CENTER component.
Not sure why the window is not centered, unfortunately I am single-monitored.
Alessandro Vernet wrote:
--
Erb
==============================================================
"Most of you are familiar with the virtues of a programmer.
There are three, of course: laziness, impatience, and hubris."
- Larry Wall
==============================================================
Thank you for the information about createCenterPanel. BTW, if you have a laptop, you can easily test this as laptops usually have a VGA output that you can setup a "second monitor" (on Windows this can done easily in the Display properties dialog).
In the meantime, a solution to this problem is to add some code to the plugin, to center the dialog relative to its parent window. Something like:
Point parentPoint = dialog.getParent().getLocation();
Dimension parentDimension = dialog.getParent().getSize();
Dimension dialogDimension = dialog.getSize();
dialog.setLocation((int) (parentPoint.getX() + (parentDimension.getWidth() - dialogDimension.getWidth()) / 2),
(int) (parentPoint.getY() + (parentDimension.getHeight() - dialogDimension.getHeight()) / 2));
Alex
Looks like "this.setLocationRelativeTo(this.getOwner())" (DialogWrapper, line 898) doesn't work for you for some reason.
I attached jar and source zip (your patch with some changes - just the location, see OpenFilesDialog.centerDialog()). Can you test if it works for you, please?
Timur
Attachment(s):
TabSwitch-0.6.5.jar
TabSwitch-0.6.5-src.zip
Hi Timur,
Sorry for the delay. I am getting the exception below when trying to switch to another file. This is with IntelliJ 3.0.4.
java.lang.NoSuchMethodError: org.tzambalayev.ideaplugins.tabswitch.OpenFilesDialog.setUndecorated(Z)V
at org.tzambalayev.ideaplugins.tabswitch.OpenFilesDialog.]]>(OpenFilesDialog.java:40)
at org.tzambalayev.ideaplugins.tabswitch.TabAction.actionPerformed(TabAction.java:30)
at com.intellij.openapi.a.b.e.a(e.java:81)
at com.intellij.openapi.a.b.e.b(e.java:13)
at com.intellij.openapi.a.b.e.a(e.java:48)
at com.intellij.ide.q.dispatchEvent(q.java:46)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Alex
Alex,
Sorry, forgot about Ariadna. Fixed (see the attachments).
Timur
Attachment(s):
TabSwitch-0.6.6.jar
TabSwitch-0.6.6-src.zip
Timur,
It works perfectly. Thank you!
Alex