Posted By:
Xhipra_Tyagi
Posted On:
Sunday, January 27, 2002 09:59 PM
Component class has a method
getParent() which returns the parent of the component. Following piece of code might make it clear:
import javax.swing.*;
import java.awt.*;
public class parentMenuItem{
public static void main(String args[]){
JMenuItem x = new JMenuItem("x");
x.setName("x");
JMenuItem y = new JMenuItem("y");
y.setName("y");
x.add(y) ;
System.out.println(y.getParent().getName());
}
}
Running the above code gives "x" as result.
Hope this helps!!