Force full redraw of a Jpanel Java2D

不打扰是莪最后的温柔 提交于 2019-12-11 03:09:16

问题


My question is that i need to make a GUI that keeps updating becuse i get values that can change from a DB and i got some problems in the graphical area.

well im using Drawline and Drawstring from Graphics2D that print values that are found on the database, this strings and lines move and change value, so i need to call repaint(); with a timer to make them apper in the jpanel, the problem is that repaint(); is not removing the old painting in the background before painting, but when i resize all updates perfecly.

i know a way to clear but the background color goes away too so, There is a way to update the jpanel removing old paintings and keep the deafult background color?

Not updated

After changing a coordenate and a label text to "AXIS Y" (repaint called automatically from a timer)

Thanks.


回答1:


From the looks of your image, it looks like you're just forgetting to call super.paintComponent in the paintComponent method. What this does is repaint the background for you, so aren't left with the previous paint artifacts.

@Override
protected voud paintComponent(Graphics g) {
    super.paintComponent(g);
}

Note: For future reference, though the images gave us a good picture, it always best to post a Minimal, Complete, and Verifiable example along with those images, so we don't have to make guesses (educated or not)



来源:https://stackoverflow.com/questions/26477521/force-full-redraw-of-a-jpanel-java2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!