Components of JFrame are only in correct position after resize (sometimes)
<p>there is this <code>JFrame</code> containg a <code>JPanel</code> containing a <code>processing</code> sketch. The code looks something like this:</p>

<pre><code>import javax.swing.JFrame;
import javax.swing.JPanel;
import processing.core.PApplet;

public class TestCase {
    public static void main(String[] args) {
        ProcessingFrame pFrame = new ProcessingFrame();
        pFrame.setVisible(true);
    }
}

@SuppressWarnings("serial")
public class ProcessingFrame extends JFrame{    
    public ProcessingFrame(){
        this.setSize(600, 400);
        this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        ProcessingSketch pSketch = new ProcessingSketch();
        panel.add(pSketch);
        this.add(panel);
        pSketch.init();
        this.setVisible(true);
    }
}

public class ProcessingSketch extends PApplet{
    public ProcessingSketch(){
        //...
    }   
    public void setup(){
        size(600, 400);
        background(200);
    }   
    public void draw(){
        rect(250,100,100,200);
    }
}
</code></pre>

<p>Too often (about 50%) the <code>panel</code> and/or <code>sketch</code> is not rendered to the appropriate location. Sometimes they are just about half of the frame size off to the right, sometimes I see just the bottom of the sketch in the frame.</p>

<p>After I resize the frame with the mouse, everything looks fine. I would like to set the JFrame to <code>undecorated</code>, but there is no way to resize the windows to put everything into place.</p>

<p>This is what I tried to solve that:</p>

<ul>
<li><p><code>JFrame.repaint()</code> as suggested here: <a href="https://stackoverflow.com/questions/8770617/java-items-appear-only-after-the-window-is-resize">Java items appear only after the window is resize</a>. - No effect.</p></li>
<li><p>I thought i could just resize the window by hand and then change to <code>undecorated</code>. Following the answer of this question: <a href="https://stackoverflow.com/questions/13979327/modifying-a-jframe-from-within-a-listener">Modifying a JFrame from within a Listener</a>. But the processing sketch crashes because I have to <code>dispose</code> the JFrame.</p></li>
</ul>

<p>Any other ideas?</p>