Skip to content

Instantly share code, notes, and snippets.

@SemenMartynov
Created April 30, 2013 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SemenMartynov/5487019 to your computer and use it in GitHub Desktop.
Save SemenMartynov/5487019 to your computer and use it in GitHub Desktop.
class ImagePanel extends JPanel {
private static final long serialVersionUID = 1L;
private Image img;
public ImagePanel(Image img) {
this.img = img;
}
public void paintComponent(Graphics g) {
int min = Math.min(getWidth(), getHeight());
Image scaledImage = img.getScaledInstance(min, min, Image.SCALE_DEFAULT);
g.drawImage(scaledImage, 0, 0, null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment