你可以再插入一个JPanel,再设置它的setBackground()为白色,再这个JPanel上画

解决方案 »

  1.   

    Graphics2D g2D = (Graphics2D) g; // Get a 2D device context
        g2D.setColor(Color.white);
        g2D.fill(new Rectangle(10,10,100,100));//填充
        g2D.setColor(Color.red);
        g2D.drawOval(30,30,50,50);//画圆可以在paintComponent中,也可以 在构建器中!很多地方都可以!
      

  2.   

    Graphics2D g2D = (Graphics2D) g; // Get a 2D device context
        g2D.setColor(Color.white);
        g2D.drawRect(10,10,100,100);
        g2D.setColor(Color.red);
        g2D.drawOval(2,2,30,30);
    放在那里都行,在构建器理调用一下!