附近其父

问题描述:

位置的JDialog我想定位一个JDialog附近它的父在这张照片显示:附近其父

enter image description here

我怎么能这样做?

感谢

你可以这样做:

JDialog.setLocation(parent.getX() + parent.getWidth(), parent.getY() + parent.getHeight() - (parent.getHeight()/2 + JDialog.getHeight()/2)); 

一个更简单的方法来做到这一点,只是引用父一次:

http://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#setLocationRelativeTo(java.awt.Component)