Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>when i try to run addSomeComponentsToFrame method, frame appears(as black rectangle) but freezes and after runOtherTask method completes it shows frame's components on screen.</p> </blockquote> <p>Sounds like you are blocking the <a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html" rel="nofollow noreferrer"><code>Event Dispatch Thread</code></a> with a long running task.</p> <p>You might want to offload that task from your EDT to a separate <em>thread</em>:</p> <p>If you manipulate Swing components in <code>runOtherTask</code> better to use :</p> <ul> <li><a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html" rel="nofollow noreferrer">Swing Worker</a> (see <a href="https://stackoverflow.com/questions/12641887/swingworker-in-java/12642215#12642215">this</a> example)</li> <li><a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html" rel="nofollow noreferrer">Swing Timer</a> (see <a href="https://stackoverflow.com/questions/14074329/using-sleep-for-a-single-thread/14074427#14074427">this</a> example)</li> </ul> <p>Otherwise you can use (Note the below does not run in the GUIs <code>Event Dispatch Thread</code> thus manipulating Swing components in them is not allowed):</p> <ul> <li><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html" rel="nofollow noreferrer">Thread</a> </li> <li><a href="http://docs.oracle.com/javase/7/docs/api/java/util/Timer.html" rel="nofollow noreferrer">Timer/TimerTask</a> (See <a href="https://stackoverflow.com/questions/11707066/timer-in-java-thread/11707987#11707987">this</a> example)</li> </ul> <p>Just as a side note no need for:</p> <pre><code>frame.getContentPane().validate(); frame.getContentPane().repaint(); </code></pre> <p>simply:</p> <pre><code>frame.validate(); frame.repaint(); </code></pre> <p>Also if your java version allows use <code>revalidate()</code> instead of <code>validate()</code>. But these are only necessary if adding/removing a component from a visible container.</p>
    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.
    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.
    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