Hi, probably a very stupid question, but I come across this for the first time, so I open a new jFrame

new ViewEditImage().setVisible(true); 

and then I want to close it.

So:

 new ViewEditImage().setVisible(false); 

So:

 jPanel1.setVisible(false); 

Nothing works

    1 answer 1

    You can try the most basic method of closing - System.exit(0) .

    Or - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Or, if you want the GUI to work as if you pressed the close button X , then you need to send the close event of the window to the Window . ExitAction from Application Closing allows you to add this functionality to a menu item or any component that easily uses an Action .

    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));

    Link to the original answer in English

    • Thanks, but solved the problem even easier, with the command dispose () - Rick Petrev
    • @RickPetrev possible and so many options. - dev3java