This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes how to dynamically resize the background image of a JPanel as the size of window changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to dynamically resize the background image of a JPanel as the size of window changes" Watch "how to dynamically resize the background image of a JPanel as the size of window changes" New topic
Author

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

aity myles
Greenhorn

Joined: Jun 14, 2011
Posts: 13
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

Joined: Jun 09, 2003
Posts: 4632
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 Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

At first simply run it and browser is after you!

I got rid of jagged edges because of scaledImage!!!

True person is moral, false is right!
aity myles
Greenhorn

Joined: Jun 14, 2011
Posts: 13
Thanks for the valuable contributions, i got it figure out through your assistance.
 
Don't get me started about those stupid light bulbs.
 
subject: how to dynamically resize the background image of a JPanel as the size of window changes