List of usage examples for javax.swing JDialog getX
public int getX()
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JDialog dialog = new JDialog(frame, false); dialog.setSize(200, 50);//from ww w . j a v a 2 s. c o m frame.addComponentListener(new ComponentAdapter() { Point lastLocation; @Override public void componentMoved(ComponentEvent e) { if (lastLocation == null && frame.isVisible()) { lastLocation = frame.getLocation(); } else { Point newLocation = frame.getLocation(); int dx = newLocation.x - lastLocation.x; int dy = newLocation.y - lastLocation.y; dialog.setLocation(dialog.getX() + dx, dialog.getY() + dy); lastLocation = newLocation; } } }); frame.setSize(400, 200); frame.setVisible(true); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); }