I'm doing this project using Swing. To add a more welcoming feel to the UI, I'm also adding a few Photoshopped images as the background.Here's where the problem begins... I want the images to automatically resize themselves once the size of the window is increased or decreased, how can I make this happen ?
One way is to override the paintComponent(...)
method of a JPanel to paint the image using the drawImage(....)
method.
Another option is use a JLabel with an Icon as the background for the frame. Then you can use the Stretch Icon which will automatically scale based on the space available to the label. This is the most flexible solution since the StretchIcon
can be used on any component that supports icons.
You can also check out the Background Panel which allows you to display an image. You can display the image at its actual size, scaled or tiled.