0

I'm working on this bug for two weeks now, and it really annoys me.

I want to set an image on a JButton, here is my code:

ImageIcon icon = new ImageIcon(this.getClass().getResource("/ecrire.png"));
        JButton b1 = new JButton(icon);
        b1.setBounds(250, 250, 192, 108);
        this.add(b1);

Here is my problem... The image appears on the button, but it seems that it is only a part of the image that appears on it, and i'd like that the whole image could be on the button her is my result in image: The result when I run the code

Frakcool
  • 10,540
  • 9
  • 46
  • 78
Dr Potato
  • 1
  • 1
  • 1
    It's really going to depend on your layout manager, but then you are 'setting bounds' That will affect the size. You need to let the layout manager manage the size. Or set it the correct size, which can change depending on the look and feel. – matt May 28 '20 at 17:19
  • 1
    I removed the last line of "please help me" that drags unnecessary attention to it. To attract the correct attention to your post please post a proper [mre] that demonstrates your issue. I agree with the comment above but still we need a MRE to see if there's something else to improve. For [example](https://stackoverflow.com/questions/44636539/ordering-image-and-text-in-jbutton/44637076#44637076) and [example](https://stackoverflow.com/questions/34230265/how-to-display-an-image-randomly-on-to-a-jbutton-using-java-swing/34232097#34232097) – Frakcool May 28 '20 at 17:28
  • 1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). E.G. [This answer](https://stackoverflow.com/a/10862262/418556) hot links to an image embedded in [this question](https://stackoverflow.com/q/10861852/418556). – Andrew Thompson May 29 '20 at 00:57

0 Answers0