When I maximize my application, the images inside of the JPanel don't resize with it. How can I make the JPanel and its contents adjust when the window is maximized?
EDIT: I am using BufferedImage
When I maximize my application, the images inside of the JPanel don't resize with it. How can I make the JPanel and its contents adjust when the window is maximized?
EDIT: I am using BufferedImage
One crude way..
That's an open ended question.
Do you want to scale to fill or scale to fit the area or don't you care about the aspect ratio??
The difference between scale to fill and scale to fit
This example will react to changes in the size of the frame and rescale the image in real time.
A better solution would be to have a background thread of some kind that could react to changes in the size of the component and rescale the original image in the background, providing a low quality and high quality scale.
It should also be noted that
Image.getScaledInstance
is neither the fastest or highest quality scaling algorithim. Take a look at The Perils of Image.getScaledInstance for more information.You might also find the following of interest
Java: maintaining aspect ratio of JPanel background image