repaint() in Java nicht "re-paint" sofort?

Habe ich einen code wie:

//In MyPanel.java
public void paintComponent(Graphics g)
{
    super.paintComponent(g);
    //Draw something
    mypanel_count++;
}

//In Test.java
public void testLargeData()
{
    while (notDone)
    {
        panel.repaint();
        //do huge work
        test_count++;
        System.out.println("Test_count: " + test_count + ", MyPanel_count: " + mypanel_count);
    }
}

//Output !!!
Test_count: 752, MyPanel_count: 23
Test_count: 753, MyPanel_count: 23
Test_count: 754, MyPanel_count: 23
Test_count: 755, MyPanel_count: 24

Aber wenn ich panel.repaint() zu panel.paintComponent(panel.getGraphics()), das stimmt:

Test_count: 752, MyPanel_count: 752
Test_count: 753, MyPanel_count: 753
Test_count: 754, MyPanel_count: 754
Test_count: 755, MyPanel_count: 755

Warum? paintComponent Methode funktioniert, aber es ist manchmal blind, so dass ich nicht wollen, es zu benutzen. Kann jemand mir einige Tipps geben? Danke!

stackoverflow.com/questions/9389187/....
vielen Dank für deine Antwort, aber es ist nicht mein ärger.
haben Sie versucht, JComponent.html#paintImmediately(int, int, int, int)
paintImmediately(...) wie vorgeschlagen von mKorbel sollte helfen.stackoverflow.com/questions/4120528/repaint-in-a-loop. Ich weiß, das ist nicht ein Antwort. Aber ich denke, die Lösung ist threads.
SwingUtilities.invokeLater arbeiten nicht für mich.

InformationsquelleAutor Bood Carley | 2012-11-19

Schreibe einen Kommentar