public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;
super.paintComponent(g2);
//背景图片
int x=0,y=0;
java.net.URL imgURL=getClass().getResource("t0156b516cea6edd501.jpg");
ImageIcon icon=new ImageIcon(imgURL);
g2.drawImage(icon.getImage(),this.getX(),this.getY(),this.getWidth(),this.getHeight(),this);
while(true){
g2.drawImage(icon.getImage(),x,y,this);
if(x>this.getWidth() && y>this.getHeight())break;
if(x>this.getHeight()){
x=0;
y+=icon.getIconHeight();
}else{
x+=icon.getIconWidth();
}
}
}
由于面板没图片大 所以图片只显示了一部分 哪位大神知道在这代码的基础上讲图片匹配上面板的大小