[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Where to put a picture files?

Hi!

I wrote a short piece of code displaying a small window and a single button. Then I wanted to put a picture on that button. That turned out to be the most difficult part! Eclipse succesfully prevented me from doing so so far but that's not it.

When I compile the java file from a command line everything works fine, there is a pretty button there. When I compile it as an Eclipse project then there is a button but no picture. I put the image file into scr directory, refreshed and hell knows what else I did but still no picture.

As I said, I was fiddling with Eclipse to find the way and I did! But now I couldn't remember what was the actual thing that made it work. So I created another class with exactly the same code and in the same package. And there is no picture there! I mean, that's just crazy. Now, when I delete that image file from src I get a complaint from Eclipse that the file is missing in both cases. I put the file back, no complaints, but only in one case the picture is on the button...

Please tell me exactly what I need to do. There is the code:

import javax.swing.*;
import java.awt.*;

public class IconButton{
	
 public static void main(String[] args){
   JFrame frame = new JFrame("Icon on button");
   JButton button = new JButton("visitscotland.org");
   Icon imgicon = new ImageIcon("icon.gif");
   JPanel panel = new JPanel();
   button.setIcon(imgicon);
   panel.add(button);
   frame.add(panel, BorderLayout.NORTH);
   frame.setSize(400, 400);
   frame.setVisible(true);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
}


Let me remind you this classic, I 100% understand the bloke:

http://www.youtube.com/watch?v=nKy9G3WkkH8