java – JPanel setBackground(Color.BLACK)什么都不做
作者:互联网
我有下面的自定义JPanel,我已经使用Netbeans GUI构建器将其添加到我的框架中,但背景不会改变!我可以看到圆圈,用g.fillOval()绘图.怎么了?
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;
}
}
解决方法:
如果您的面板“不透明”(透明),您将看不到您的背景颜色.
标签:setbackground,java,background,swing,jpanel 来源: https://codeday.me/bug/20191007/1868978.html