Java buffer strategy sometimes doesn't draw properly
<p>I created a game in Java which uses buffer strategy. But sometimes I just get a white frame or a white border. That happens about every fifth time. I searched a lot but I really can't figure out what I'm doing wrong. The code compiles and there aren't any errors printed out.</p>

<p>If if fails, the frame looks for example like that:</p>

<p><a href="http://i.stack.imgur.com/7UUHg.png" rel="nofollow">white border</a></p>

<p><a href="http://i.stack.imgur.com/3bQ2n.png" rel="nofollow">completely white frame</a></p>

<p>Here's code (only the relevant parts):</p>

<pre><code>private BufferStrategy bs;
public Testclass(){
    setResizable(false);
    setSize(1000,600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setIgnoreRepaint(true);
    setVisible(true);
    createBufferStrategy(2);
    bs = getBufferStrategy();
}

protected void paint() {
    do {
        Graphics2D g=null;
        try {
            g = (Graphics2D) bs.getDrawGraphics();
            g.setColor(Color.CYAN);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
        } finally {
            g.dispose();
        }
        bs.show();
    } while (bs.contentsLost());
}

public static void main(String[] args) {
    Testclass window = new Testclass();
    window.paint();
}
</code></pre>