Java: maintaining aspect ratio of JPanel background image

Well, the quickest and easiest solution is to use Image.getScaledInstance g.drawImage(img.getScaledInstance(newWidth, -1, Image. SCALE_SMOOTH), x, y, this); If your wondering about the negative number, the java docs say: If either width or height is a negative number then a value is substituted to maintain the aspect ratio of the original image dimensions. If both width … Read more