0

Ali this is what i have now done, but i am now getting the error non static method getClass() cannot be referenced from a static context

 buttonc = new JButton("6");
    cc.fill = GridBagConstraints.HORIZONTAL;
    cc.ipady = 20;       //reset to default
    cc.weightx = 0.0;   //request any extra vertical space
//    c.anchor = GridBagConstraints.LAST_LINE_START; //bottom of space
//    c.insets = new Insets(10,0,0,0);  //top padding
    cc.gridx = 1;       //aligned with button 2
    cc.gridwidth = 1;   //2 columns wide
    cc.gridy = 2;       //third row
    pane.add(button, cc);

        try{
       Image  img = ImageIO.read(getClass().getResource("gui/UpdateLib.png"));
       Image resize = img.getScaledInstance(290, 180, java.awt.Image.SCALE_SMOOTH);
       buttonc.setIcon(new ImageIcon(resize));

        }catch(Exception e){
        }
Reynolds
  • 9
  • 5
  • Ahh, what's wrong with [`JButton#setIcon`](http://docs.oracle.com/javase/7/docs/api/javax/swing/AbstractButton.html#setIcon(javax.swing.Icon))? You might like to take a look at [How to use buttons](http://docs.oracle.com/javase/tutorial/uiswing/components/button.html) – MadProgrammer Dec 29 '13 at 00:04
  • I have recommended the poster to look at the very link in my answer. – Ali Gajani Dec 29 '13 at 00:05

1 Answers1

0

You should consider looking at the Java Docs here.

ImageIcon img = createImageIcon("img/photo.gif");

Once you've set the image, you can add it to your JButton using:

button = new JButton("6", img);
Ali Gajani
  • 14,762
  • 12
  • 59
  • 100