Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to dynamically resize the background image of a JPanel as the size of window changes

 
aity myles
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have just successfully added a background image to a JPanel by overriding the paintComponent method, however i realized that each time i maximize the window containing the JPanel, the image doesnt re-adjust to completely fill up the the window. The size of the background image remains static irrespective of the size of the window. i want the background image to dynamically fill up the the JPanel each time the window is resized.
Thanks in advance for your assistance
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it the panel, or the image, that is not resizing?

if the panel, use a correct layout manager.

if the image, use the correct parameters
i.e. panel has getWidth() and getHeight()
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At first simply run it and browser is after you!

I got rid of jagged edges because of scaledImage!!!
 
aity myles
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the valuable contributions, i got it figure out through your assistance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic