Originally Posted by
mohsen.noor
Image image = new ImageIcon("netbeans.png").getImage();
The main question is that "netbeans.png" is a specification on the file-system and, more important, it's a
relative specification ....
relative to the "current" directory.
What is your current directory when you launch your application-in-jar? I can't know .... it depends. Depends on how/from where you start the java launcher (java.exe o whatever is in other O.S.).
To be clear: your jar is for example in C:\MyProjects\myapp.jar
From command prompt you can do:
C:\MyProjects>java -jar myapp.jar
or
C:\>java -jar MyProjects\myapp.jar
Both commands (in blue) correctly start your jar .... but the "current" directory is different ("C:\MyProjects" the first, "C:\" the second time).
If your image "belongs" to your application, you should load it as a "resource" using getResource/getResourceAsStream of java.lang.Class.
If "netbeans.png" is in the same package of MyPanel, you can do:
ImageIcon ii = new ImageIcon(MyPanel.class.getResource("netbeans.png"));
And it works even if netbeans.png is
into the jar.
Final note: don't load images (any resource in general) in a paint/paintComponent method.