is there a way to get the top level container of a component? For example I have a JToolbar and I want to know at one monent the top level container of that JToolbar is my JFrame or is its own window, a JDialog.
+1
A:
If the component has been added to the hierarchy, you can look up the top-level container by recursively calling getParent
:
Container c = toolbar;
while ( c.getParent() != null )
{
c = c.getParent();
}
if ( c instanceof JFrame )
{
//...
}
Ash
2010-04-18 03:05:36