java - Swing Component (re)paint mechanism fails to properly draw, when requests are too fast -
from java's documentation says repaint mechanism of component optimized , cached, if called lot of times, won't clog drawing pipeline.
it seems though under heavy invocation, fails draw latest frames. consider following example:
import java.awt.graphics; import java.awt.event.mouseadapter; import java.awt.event.mouseevent; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.windowconstants; public class testrepaint extends jpanel { public static void main(string[] args) { jframe frame = new jframe(); frame.setcontentpane(new testrepaint()); frame.setsize(300, 100); frame.setdefaultcloseoperation(windowconstants.dispose_on_close); frame.setlocationrelativeto(null); frame.setvisible(true); } private long start; { addmouselistener(new mouseadapter() { @override public void mouseclicked(mouseevent e) { start = system.currenttimemillis(); system.out.println("repaint"); repaint(); } }); } @override protected void paintcomponent(graphics g) { super.paintcomponent(g); long = system.currenttimemillis(); int = (int) ((now - start) / 5); if (where >= 200) g.drawstring("done", 200, 30); else { g.drawstring("working...", where, 30); repaint(); } } }
when mouse clicked on window, "working..." text scroll right. on last frame supposed change "done". seems (randomly) fails draw last frame , previous "working..." text remains. if example force redraw display (i.e. change window size), "done" appears.
it seems that, since repaint requested fast, last repaint of component fails happen. so, there guaranteed way this?
Comments
Post a Comment