• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image in JLabel

 
Nouf Nassri
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nouf Nassri
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2676
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic