rendered paste bodypublic class ILabel extends JLabel implements ImageObserver {
private Image img;
public ILabel() {
super();
}
public void setIcon(ImageIcon ico) {
img = ico.getImage();
//Should I call super()? Nah.
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(img==null)
return;
int w = img.getWidth(this);
int h = img.getHeight(this);
if(w<=getWidth() && h<=getHeight()) {
double scalefactor = (double)Math.max(w, h) / Math.max(getWidth(), getHeight());
w = (int)scalefactor * w;
h = (int)scalefactor * h;
img = img.getScaledInstance(w, h, Image.SCALE_SMOOTH);
}
g.drawImage(img, w, h, this);
}
}