我创建了一个在jPanel
中显示图像的组件。但它在设计时没有显示图像。如何在设计时显示图像?
public class JImagePanel extends JPanel {
private BufferedImage _img=null;
public JImagePanel() {
super();
}
public void setImage(URL img) {
try{
this._img = ImageIO.read(img);
validate();
repaint();
}catch(Exception err){
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if(this._img!=null)
g.drawImage(_img, 0, 0, getWidth(), getHeight(), this);
}
}