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:

saveDialog.setLocationRelativeTo(menuBar);

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?

5 comments

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:

WindowManager.getInstance().getFrame(project)

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

0

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:

WindowManager.getInstance().getFrame(project)


I also tried

WindowManager.getInstance().getFrame(project).getRootPane()


and

WindowManager.getInstance().getFrame(project).getRootPane().getParent()



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.



Attachment(s):
Screenshot - 04012013 - 04:20:29 PM.png
0

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

0

Ok, what about the green and yellow positions?

0

AFAIK there is no API for green and yellow positions.

0

Please sign in to leave a comment.