Java examples for java.awt:Component
Swing component Is In Container
//package com.java2s; import java.awt.Dimension; import java.awt.Point; import javax.swing.JComponent; public class Main { public static boolean componentIsInContainer(JComponent container, JComponent component) { Point p = container.getLocation(); Point xy = component.getLocation(); Dimension d = container.getSize(); if ((xy.x > p.x && xy.x < p.x + d.width) && (xy.y > p.y && xy.y < p.y + d.height)) { return true; } else {/*from w w w . j a va2 s.c o m*/ return false; } } }