Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPanel setBackground(Color.BLACK) does nothing

I have the folowing custom JPanel and I have aded it to my frame using Netbeans GUI builder but the background won't change! I can see the circle, drawing with g.fillOval(). What's wrong?

public class Board extends JPanel{

    private Player player;

    public Board(){
        setOpaque(false);
        setBackground(Color.BLACK);  
    }

    public void paintComponent(Graphics g){  
        super.paintComponent(g);
        g.setColor(Color.red);
        g.fillOval(player.getxCenter(), player.getyCenter(), player.getRadius(), player.getRadius());
    }

    public void updatePlayer(Player player){
        this.player=player;
    }
}
like image 744
c0dehunter Avatar asked Apr 13 '12 21:04

c0dehunter


1 Answers

setOpaque(false); 

CHANGED to

setOpaque(true);
like image 86
Nilesh Jadav Avatar answered Sep 20 '22 19:09

Nilesh Jadav