aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Image in JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image in JLabel" Watch "Image in JLabel" New topic
Author

Image in JLabel

Nouf Nassri
Ranch Hand

Joined: Apr 22, 2010
Posts: 40
Hello everyone,
I still have a problem. I'd like to put an image in a JLabel or JButton but every time I load the component,
the component resizes depending on size of the image. My problem is that how you want the image to resize
depending on the size of the button or label.

thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42637
    
  65
The size of a button or label depends on the size of its content, not the other way around. If you want a small button/label, make sure it has small contents (maybe by scaling the image down).

Also check out the button's/label's set[Preferred|Minimum|Maximum]Size methods.


Ping & DNS - my free Android networking tools app
Nouf Nassri
Ranch Hand

Joined: Apr 22, 2010
Posts: 40
I put an image in a label but with a format resize




I am able to view the image, but it does hold myself part of the image

I see all but narrowed

how?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
There is no way we can tell what you are doing wrong based on the code you posted.

Read the JLabel API and follow the link to the Swing tutorial on "How to Use Labels" for working examples. There is also a section on "How to Use Icons", that gives more examples of how to properly read an image.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image in JLabel