How to get the window of two different components?

Hi!

Is there a way to elegantly get the window where two Components reside?

The other component is a button directly in the main layout of the window and the other is a Field nested in a layout within a layout within a layout and so on. So, would there be a way to get the parentwindow of the Field without a monstrous “…getParent().getParent().getparent()…” method call?

Thank you.

I doubt that there is a direct way to do it (like a getParentWindow-method) but at least you could automate it a bit using a method like this:

public Window getParentWindow(AbstractComponent comp){ while(comp instanceof Window == false){ comp = (AbstractComponent) comp.getParent(); if(comp == null || comp instanceof UI){ System.out.println("Comp has no parent Window"); return null; } } return (Window) comp; } This little function i made should always return an instance of the Window in which the component is embedded.
Usage example:

Window wind = getParentWindow(button);

That’ll become handy. Thanks!