tags:

views:

32

answers:

2

hello all i have an application with two main panel LEFT and RIGHT when a component got focus i want to know how is the container that holds that component (LEFT or RIGHT) the component can be inside some other panel's , but eventually sits inside the LEFT or RIGHT panel

is there a more simple way to know who is the container without running in loop on get parent each time a component got focus

thank you

+1  A: 

Try this one. It discusses about the SwingUtilities class http://stackoverflow.com/questions/1938774/jlabel-get-parent-panel/1940703#1940703

zapping
thats greate , using the SwingUtilities.getAncestorOfClass(Class, Component)i can find my class by type .i was thinking the solution is using somehow the focus cycle root
shay
A: 

i think i got it

pnla.setFocusCycleRoot(true);
pnla.setFocusTraversalPolicy(new JTPCScreenMainFocusTraversalPolicy());

pnlb.setFocusCycleRoot(true);
pnlb.setFocusTraversalPolicy(new JTPCScreenOptionsFocusTraversalPolicy());

and when component focused i ask for

component.getFocusCycleRootAncestor() instance of PNL_A 

thanks

shay