Example usage for java.awt Component contains

List of usage examples for java.awt Component contains

Introduction

In this page you can find the example usage for java.awt Component contains.

Prototype

public boolean contains(Point p) 

Source Link

Document

Checks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the coordinate system of this component.

Usage

From source file:Main.java

private void myPaint(Component comp, Graphics g) {
    int x = comp.getX();
    int y = comp.getY();
    g.translate(x, y);//from w w  w  . j a v a2  s .  c om
    cursor.translate(-x, -y);
    if (comp.contains(cursor)) {
        String cls_name = comp.getClass().getName();
        g.setColor(Color.black);
        g.drawString(cls_name, 0, 10);
    }
    if (comp instanceof Container) {
        Container cont = (Container) comp;
        for (int i = 0; i < cont.getComponentCount(); i++) {
            Component child = cont.getComponent(i);
            myPaint(child, g);
        }
    }

    cursor.translate(x, y);
    g.translate(-x, -y);
}

From source file:edworld.pdfreader4humans.PDFReader.java

protected Component findContainer(Component component, List<? extends Component> containers) {
    Component container = null;/*from  ww  w. ja  va  2s  .  co m*/
    float area = Float.POSITIVE_INFINITY;
    for (Component possibleContainer : containers)
        if (possibleContainer.contains(component) && possibleContainer.getArea() < area) {
            container = possibleContainer;
            area = possibleContainer.getArea();
        }
    return container;
}