How do I know the parent JMenuItem of another JMenuItem from JMenuItem
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anshul_Chhabra
Posted On:   Saturday, January 26, 2002 04:21 PM

Example

JMenuItem x ;
//.. do initialization here

JMenuItem y ;

x.add(y) ;


From y, can I get x?

Re: How do I know the parent JMenuItem of another JMenuItem from JMenuItem

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!!
About | Sitemap | Contact