I decided to put "close" buttons on my JFrames. If I test just that JFrame by itself, it works fine, but when I try to close it after opening it through another class, it won't close.
Here is the code:
JButton btnClose = new JButton("Close");
btnClose.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
frame.dispose();
}
});
btnClose.setBounds(282, 666, 96, 50);
contentPane.add(btnClose);
I have tried using frame.dispose()
and frame.close()
and super.dispose()
but the only one that works is system.exit(0);
but then that exits the whole program.
The issue:
- If I test the
JFrame
by itself, the frame closes fine. - If I open the program and navigate to that specific
JFrame
, the close button does nothing.
Please advise.