Note that there are some explanatory texts on larger screens.

plurals
  1. POClose JFrame from a JButton process remain alive
    primarykey
    data
    text
    <p>I have a class developed with windowbuilderpro that i want to close also from a JButton further than with the standard X button on the window, so here the example of the class : </p> <pre><code>public class MainWindow { public JFrame frame; public MainWindow() { initialize(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } public void show() { EventQueue.invokeLater(new Runnable() { public void run() { try { //Show the main Frame frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } </code></pre> <p>When i close the window from the X button the window close correctly and the process terminate.</p> <p>When i close instead from a JButton that have this listener : </p> <pre><code>mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //Close the application main form frame.setVisible(false); frame.dispose(); } }); </code></pre> <p>the frame window close correctly but the process remain alive ... Why ?</p> <p><img src="https://i.stack.imgur.com/fl6Jz.png" alt="Process Alive"></p> <p>As you can see there is an AWT-Shutdown thread that start and terminate continuously, How can i achieve the same behaviour of the X button that close also the application process ?</p> <p><strong>Notes :</strong> </p> <p>System.exit(0); is not suitable because it terminate the application also if there are another background running thread and i don't want that . The MainWindow class should close and release it's resource, the same behaviour that have closing the application with the X button that close the MainWindow instance but if there are background thread running it doesn't kill they but wait until they finished their work...</p> <p><strong>Enviroment :</strong> </p> <ul> <li>JDK 7</li> <li>Eclipse 3.7.1</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload