2

I want to add images to JButtons. Here is the code I am using:

The images are in a folder called "Images", which happens to be in the source package of the application. The size of the JButtons is adjusted correctly, however no image is displayed in the button. Can someone help me solve this problem please? Thanks :)

Matthew
  • 4,477
  • 21
  • 70
  • 93
  • 1
    You could take a look at [this to compare](http://stackoverflow.com/questions/12691832/how-to-put-an-image-on-a-jbutton) – bonCodigo Nov 14 '12 at 11:39
  • Please have a look at how to [add images to your Project](http://stackoverflow.com/a/9866659/1057230) and this [answer](http://stackoverflow.com/a/11372350/1057230) for more clarification, if you doing it manually. – nIcE cOw Nov 14 '12 at 12:20

1 Answers1

3

Try create_ImageIcon(Button_NewFile, "src/Images/New File.png");

When you create an ImageIcon, it searches for relative paths where the application is launched. Normally this is in the folder where src folder is located. But have in mind that when you run it as an independent application.

Juvanis
  • 25,802
  • 5
  • 69
  • 87