@Override public void show(Component c, int x, int y) { System.out.println(c.getClass().getName()); if (check.isSelected()) { Point p = new Point(x, y); Rectangle r = c.getBounds(); Dimension d = getPreferredSize(); if (p.x + d.width > r.width) { p.x -= d.width; } if (p.y + d.height > r.height) { p.y -= d.height; } super.show(c, Math.max(p.x, 0), Math.max(p.y, 0)); } else { super.show(c, x, y); } } };