I have a menu bar class (MenuBarGUI) that I have put in all of my other classes and I need to know if I can close the current JFrame that it is contained in through an option in the menu. Normally I could call setVisible(false) then dispose() but because the menu bar doesn’t have a reference to the current frame, I can’t do that. Is there any way to do this?
Share
if your MenuBarGUI class extends JMenuBar, you can use getTopLevelAncestor method to get menu bar’s window.