是否可以关闭组件的父元素..可能是来自JPanel的JFrame
/ JInternalFrame
?如果是的话怎么做?
答案 0 :(得分:4)
这将对您有所帮助:
SwingUtilities.windowForComponent(panel).dispose();
或
SwingUtilities.windowForComponent(panel).setVisible(false);
答案 1 :(得分:2)
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 );
}
}