views:

21

answers:

2

I add an image to the button in the following way:

ImageIcon icon = new ImageIcon("images/col.jpg");
tmp = new JButton(icon);

My image is a red sphere but in my button I see only read color. I assume that I see just a small part of the sphere. How can I see the whole image in the button?

ADDED

Yes, my icon is bigger than the button. Is there a simple way to force the icon to fit the size of the button?

A: 

You could add some screenshot to clear things a little more.

Some quick first thoughts:

  • your image is larger than the icon space in the button
  • try to modify the button border and/or insets
  • keep in mind that different themes might show different results
Daniel Bleisteiner
+1  A: 

Maybe the icon is bigger than the button? You could try to downscale the image by first loading an Image and then calling Image.getScaledInstance().

Edit: Of course the even simpler way is to resize the original file.

fish