public static final Component getChildAtLine(Container container, Point p, boolean horizontal) {
    if (horizontal) {
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component c = container.getComponent(i);
        if (p.x >= c.getX() && p.x < c.getX() + c.getWidth())
          return c;
      }
    }
    else {
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component c = container.getComponent(i);
        if (p.y >= c.getY() && p.y < c.getY() + c.getHeight())
          return c;
      }
    }

    return null;
  }