开发者

Graphics#drawText, old text does not get erased

I have a JPanel which overrides paintComponent like this

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);    
    //[...]
    g.drawString(" x " + model.getCount(l), getTilesWidth() + ship.getWidth() + PREVIEW_OFFSET开发者_C百科_X + 5, y - 10);
    //[...]
}

but when I call repaint and model.getCount(l) has changed, the new string gets just drawn above the old string. However, when I resize the window everything is fine again. What could be the cause for this?


Most likely you need to fill in the area where the old text was with the background color before attempting to draw the new text.


ooops, the error was actually elsewhere, I really forgot that my class had a superclass other than JPanel, sorry for that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜