*
The moose likes Swing / AWT / SWT and the fly likes Image Resize on window Resize Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image Resize on window Resize" Watch "Image Resize on window Resize" New topic
Author

Image Resize on window Resize

Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 497

Hi,

Please have a look at the following code



In here what I am trying to do is to re size the image applied to the JLabel on window resize. But my image is not getting resized. Please help..


Are you better than me? Then please show me my mistakes..
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 497

Can someone help me please?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
have the image drawn via the label's paintComponent where the width/height is a % of the frame's size
(or perhaps % of label's container's size, if it also increases/decreases along with frame)
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2091
    
    7
Check out Background Panel for an example that dynamically resizes the image as the size of the panel changes.
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 497

Seems like this is harder than I thought. Never mind, I will give a try, thanks to all of you for the replies
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2091
    
    7
Its not that hard. Its one line of code to draw an image at the size of the container.

The code I gave you does lots of other stuff as well that you don't need.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

i had the opposite question. window resize based on image size. but i will save it for another post.


SCJP
Visit my download page
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 497

I will have a look now
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Randall Twede wrote:i had the opposite question. window resize based on image size. but i will save it for another post.

Since the answer is brief, I'll provide it here (sorry Yohan!). In the (J)component that paints the image, override getPreferredSize to return the size of the image. Then call pack() on the window it's shown in.

luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image Resize on window Resize
 
Similar Threads
I want help with display
java.net.SocketException: Error
Unable to save a file using JFileChooser
Error in NapKin Look and Feel
Multiple controls in a panel