I read that you shouldn’t .show() frames on the main thread to avoid deadlock, is this a real problem. Should this always be avoided? Also once you display any sort of dialog box, such as a ProgressMonitorInputStream, even if it closes and is done, must you still call System.exit() to kill the app? What about a JDialog?
I read that you shouldn’t .show() frames on the main thread to avoid deadlock,
Share
It’d stop reading that book/post/webpage.
To address your first point:
I think you may be missing some points.
All UI code MUST be executed on the Event Dispatching Thread (EDT), this includes UI components that aren’t even on the screen yet.
You should NOT perform time consuming tasks one the EDT as this will prevent the screen from been updated and make your application non-responsive, which users really, really hate.
Time consuming tasks should be performed in there own Thread (this is actually an entirely different topic), using some thing like SwingWorker or SwingUtilities.invokeLater/andWait to resync/update the UI.
To address your second point:
Yes and no. The
JFrameclass provides a defaultCloseOperation which you can use to terminate the main application.However, if all you ever display is
JDialogor other type of window, yes, you will need to callSystem.exitin order to terminate the JVM.Where it’s supported, you can use a WindowListener.windowClosed event to monitor when you window is closed and take appropriate action.