Darshan Patni
Darshan Patni

Reputation: 3

How to close parent frame from JInternalFrame in java?

I want to close the parent frame on the click of a button in JInternalFrame.

Upvotes: 0

Views: 1008

Answers (1)

Mattias Isegran Bergander
Mattias Isegran Bergander

Reputation: 11909

Parent frame as the JInternalFrame the button is in or the JFrame or window it is contained in? Use either:

SwingUtilities.getWindowAncestor(button).dispose()

or

SwingUtilities.getAncestorOfClass(JInternalFrame.class, button).dispose();

or similar.

Javadoc: https://docs.oracle.com/javase/8/docs/api/javax/swing/SwingUtilities.html

Upvotes: 1

Related Questions