Positioning of UI Elements

I have various JBPopup and JDialog Elements which i want to position on the screen. I managed to get the menu bar component like this:

JMenuBar menuBar = WindowManager.getInstance().getFrame(project).getJMenuBar();

The dialog can be positioned with:


The popup with:

JBPopupFactory.getInstance().[...].show(RelativePoint.getCenterOf(menuBar), Balloon.Position.atRight);

I want to be able to position components at other locations:

  1. next to the tab bar
  2. at current mouse position
  3. at the center of the IDE window

How can i do that?

Comment actions Permalink

1. I'm not sure I understand this "next to" location. It is just below editor tabs? Or it is empty space in tabs row?
2. If you have MouseEvent as trigger to show dialog, you can use its location. In general you can obtain current mouse position with java.awt.MouseInfo#getPointerInfo()
3. I can combine it from  from your own example:


is good parameter for setLocationRelativeTo(), isn't it?

Comment actions Permalink

Thanks for your answer.

1. Both is interesting for me
2. Yes, that should do the trick
3. Works basically, but is not really centered on the screen

I attached an image for better understanding. The red area is where  the following relativeTo component places the dialog:


I also tried




All with the same result. The green area is where i'd like to display the dialog instead. The yellow area is where i'd like to position my JBPopup. Also, i'd like to know how to center a dialog in the whole IDE window.

Screenshot - 04012013 - 04:20:29 PM.png
Comment actions Permalink

Try call dialog.pack() and then setLocationRelativeTo(). Top left corner is exactly in the center of screen.

Comment actions Permalink

Ok, what about the green and yellow positions?

Comment actions Permalink

AFAIK there is no API for green and yellow positions.


Please sign in to leave a comment.