java-Swing-paintComponent

class MyPanel extends JPanel{
    public void paintComponent(Graphics g)
    {
         super.paintComponent(g); 
         g.setColor(Color.red);
         g.fillRect(10,10,80,30);
    }
}

不调用super.paintComponent(g)的话,repaint()的时候就会把你写的paintComponent中的内容绘制上去。如果你调用super.paintComponent(g),那么就会把整个组件彻底清空(恢复到父类时的状态),然后依次再绘制。

发布了74 篇原创文章 · 获赞 23 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qxhly/article/details/78633697
今日推荐