Java/Swing: Obtain Window/JFrame from inside a JPanel

You could use SwingUtilities.getWindowAncestor(...) method that will return a Window that you could cast to your top level type.

JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);

Leave a Comment