Find the Window that a component is being displayed inside of?
843805Feb 10 2006 — edited Feb 16 2006Hello all. I need to find out if a component is being displayed inside of a Window (or JWindow/Frame/JFrame). I need to get the reference for the window component that the component is in.
I've tried using various combinations of methods in SwingUtilities, as well as Component.getParent(), etc., and can't seem to be able to get what I am looking for.
For example, I have a JPanel nested inside of another JPanel that is nested inside of a JFrame, and I want to get a reference of the JFrame. If I use a getParent() call recursively I only get to the parent JPanel, and not to the JFrame.
I'm trying to write a generic method in my extended JPanel class that determines if its sitting inside of a Window/JWindow/Frame/JFrame, and if so, if the window has a JMenuBar. Specifically I'm trying to get a list of all JMenu objects that a window may have that my JPanel subclass is sitting inside (don't want to assign a mnemonic value if its already being used by a JMenu object).
Any advice/information would be appreciated. Thank you in advance for your time.