Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The answer is simple: No you cannot have 2 <a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html" rel="nofollow">EDTs</a>, that is not possible. But you are not stuck with a frozen GUI, you have some options available.</p> <p>First and foremost, two important rules:</p> <ol> <li><strong>Never</strong> do lengthy calculations in the EDT. Ever.</li> <li><strong>Never</strong> manipulate Swing components from outside the EDT. Ever.</li> </ol> <p>Breaking the first rule will result in your GUI being frozen and no events of any sort being processed during that time. This includes updates to the GUI you want to do during the calculations which will not appear until after the calculations are done.</p> <p>The latter is often ignored which will go by unnoticed most of the time, but it can - and will - bite you in the ass and then most of the time it is a huge pita to go back and fix it. So do it the correct way from the start. What can happen? Components can suddenly display in a broken state, they may appear white, or the whole application can freeze because there is a deadlock between the EDT and your other threads (been there, done that). Adhere to the <a href="http://docs.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading" rel="nofollow">Oracle Swing Threading Policy</a>!</p> <p><br/> So, how to avoid doing lengthy calculations on the EDT after for example the user pressed a button? Options:</p> <ul> <li>use a <a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html" rel="nofollow">SwingWorker</a>. Advantage: Has a <code>done()</code> method you can use which is automatically executed in the EDT once the worker is done. Also implements the <code>Future</code> interface and can therefore be used to return a result.</li> <li>you can just create your own <code>Runnable</code> and do the calculations in there.</li> <li>use any other way Java provides for parallel execution.</li> </ul> <p>Ok, and how to avoid <strong>ever</strong> manipulating GUI from outside the EDT?</p> <ul> <li>call <code>SwingUtilities.invokeLater()</code> and execute Swing manipulations in there.</li> <li>use the SwingWorkers <code>done()</code> method as described above.</li> </ul> <p>If you follow these two rules, your Swing GUI will be in a much better shape and you can focus more on your application development rather than Swing issues.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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