问题
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