Hi all

In the book im learning from 'Getting Started In Java' one of the example programs is a small swing application with some buttons and icons on the buttons.
I typed the code and the book tells me to place my picture that i want to use as an icon in the bin directory of my jdk folder so my picture butt1.gif is in
C:\Program Files\Java\jdk1.6.0_07\bin\butt1.gif
The picture they use in the book is 50x50 in size so i found one on the web and placed it in the folder and called it butt1.gif. When i compiled the code it went fine but when i ran the code the window appears and the button but only as tiny spec maybe only a pixel is shown in the button where the icon is supposed to be.
I rechecked my code but it all looks good and i even removed two of the buttons so i only had one button with the butt1.gif shown inside it but still only a pixel is shown.
Here is my code

import javax.swing.*;

public class selFunction extends JFrame
{
  ImageIcon scope = new ImageIcon("butt1.gif");
  JButton osc = new JButton(scope);
  // i removed two of the buttons just to see if only one would work

  
  
  public selFunction()
  {
    super("Select a function");
    setSize(350, 100);
    
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel funcs = new JPanel();
    funcs.add(osc);
    
    
    setContentPane(funcs);
  }
  
  public static void main(String[] args)
  {
    selFunction NIECfuncs = new selFunction();
    NIECfuncs.setVisible(true);
  }
}

I have tried with a different pic and that pic was 591x655 but still only a pixel is shown on the button.

Can anyone tell me why its not working please?

Many thanks

HLA91

The book is either to old or it is wrong reading, you do not want to add extra things to your Java home directory. If you need to add something you would normally set CLASSPATH to folder where the content is stored. The image you want to use need to be in same folder as the final class file you get after compile...

OK thanks, i think the book assumes you are compiling in the actual bin directory , i followed your instructions and it was all good, thanks alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.