Hello Good day. I have an interesting question as it relates to adding a background image to a JPanel (or whichever component is best for what I'm trying to achieve. Hopefully I'll get some help here.)
I have a large picture that I want to use as a background image and I want it to be the background for my JFrame. The only thing is that I don't want the image to resize when the JFrame resizes. I want the image to remain centered in relation to the JFrame's position and size, but I just don't want the view of the image to shrink in size. Any suggestions please?
I'll gladly clarify where needed.
Here's a pictorial illustration.
depends on how you are doing it - do you override paintComponent or is it a JLabel with an ImageIcon?
If it's paintComponent then just draw the image at (panel width - image with)/2, (panel height - image height)/2. Your paintComponent will be called after any resize and will always center the image.
If it's a JLabel then it also depends on the layout manager...