Is it possible to close parent element of a component .. probably a JFrame/JInternalFrame from a JPanel? if yes how it can be done?
Asked
Active
Viewed 1,174 times
2
Andrew Thompson
- 166,747
- 40
- 210
- 420
c.pramod
- 606
- 1
- 8
- 22
2 Answers
4
This will help you:
SwingUtilities.windowForComponent(panel).dispose();
or
SwingUtilities.windowForComponent(panel).setVisible(false);
Dan D.
- 32,096
- 5
- 61
- 79
2
Modified version of this answer
public class CustomPanel extends JPanel {
private JFrame parent; //Need to pass this reference somehow, constructor or otherwise
public void closeJFrame() {
WindowEvent winEvent = new WindowEvent(parent, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winEvent );
}
}