Here you can find the source of calcLocation(JFrame main, JDialog dialog)
public static Point calcLocation(JFrame main, JDialog dialog)
//package com.java2s; //License from project: LGPL import javax.swing.*; import java.awt.*; public class Main { private static final int SCREEN_WIDTH = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth(); public static Point calcLocation(JFrame main, JDialog dialog) { int mainWidth = main.getWidth(); int mainX = main.getX(); int dialogWidth = dialog.getWidth(); int x;//w ww . ja va2 s. c om if ((mainX + mainWidth + dialogWidth) > SCREEN_WIDTH) { x = mainX - dialogWidth - 50; } else { x = mainX + mainWidth + 50; } return new Point(x, 50); } }