1 Replies - 1022 Views - Last Post: 10 April 2014 - 12:25 AM Rate Topic: -----

#1 ImprovasaurusBultrowicz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 25-March 14

Help with adding an image to a button

Posted 09 April 2014 - 06:41 PM

I am trying to add an image to this button.
 button3 = new JButton();
      button3.setIcon(new Image("C:\\Users\\Owner\\Desktop\\AUSE.jpg"));
      button3.setEnabled(true);
      panel.add(button3);
      add(panel);



Any help with this error I am getting?
BackgroundImageHelper.java:77: error: Image is abstract; cannot be instantiated
      button3.setIcon(new Image("C:\\Users\\Owner\\Desktop\\AUSE.jpg"));
                      ^
1 error

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.
[\code]

[quote name='ImprovasaurusBultrowicz' date='09 April 2014 - 06:38 PM' timestamp='1397093920' post='1995854']
I am trying to add an image to this button.
[code]
 button3 = new JButton();
      button3.setIcon(new Image("C:\\Users\\Owner\\Desktop\\AUSE.jpg"));
      button3.setEnabled(true);
      panel.add(button3);
      add(panel);



Any help with this error I am getting?
BackgroundImageHelper.java:77: error: Image is abstract; cannot be instantiated
      button3.setIcon(new Image("C:\\Users\\Owner\\Desktop\\AUSE.jpg"));
                      ^
1 error

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.


[/quote]

BackgroundImageHelper.java:77: error: Image is abstract; cannot be instantiated
      button3.setIcon(new Image("C:\\Users\\Owner\\Desktop\\AUSE.jpg"));
                      ^
1 error

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.




Technical difficulties posting haha, THIS IS THE ERROR.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with adding an image to a button

#2 mike73   User is offline

  • D.I.C Addict
  • member icon

Reputation: 250
  • View blog
  • Posts: 918
  • Joined: 24-April 10

Re: Help with adding an image to a button

Posted 10 April 2014 - 12:25 AM

You need an image icon, not an image.

Image img = ImageIO.read(getClass().getResource("resources/water.bmp"));
button.setIcon(new ImageIcon(img));

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1