• Post Reply Bookmark Topic Watch Topic
  • New Topic

fit the image to the button size

 
chen young
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to add an image to a button



unfortunately the image is changing also the button size so all the screen is corrupt.

How can I fit the image to the button size ?

Thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way of doing it is overriding the paintComponent and drawing the image yourself. Use the appropriate Graphics#drawImage() where you can define the image size.
You will need to set the Image size to the button dimensions, which you can obtain by getWidth() and getHeight()
 
chen young
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What do you mean by using “Graphics#drawImage()” ?
How can I implement drawImage on Jbutton ?

can you please add example

Thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the Swing FAQ.
There is a link to drawing an image on the panel as a background.
Also check your private messages for an important administrative matter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!