@Override public void paintComponent(Graphics g) { super.paintComponent(g); // resize picture to appropriate size ImageIcon newPicture = GUI.scaleImage(picture, PICTURE_WIDTH, PICTURE_HEIGHT); int width = newPicture.getIconWidth(); int height = newPicture.getIconHeight(); // get offsets in order to center picture int verticalOffset = (PICTURE_HEIGHT - height) / 2; int horizontalOffset = (PICTURE_WIDTH - width) / 2; // if the image is thinner than this panel, offset it // paint the picture g.drawImage(newPicture.getImage(), horizontalOffset, verticalOffset, this); // offsets let the image be centered }