java - Inserting icons in downloadable jar application -



java - Inserting icons in downloadable jar application -

i novice programmer trying create jar file people can download , demonstrates a...jrpg-ish upgrade scheme have. little visual pop, want central button display little icon visual pop. while works fine in eclipse, when export jar file icon no longer displaying (though rest of programme works intended.

i have managed create eclipse import files want jar file, seen below.

this code have display them in eclipse

imgdin = new imageicon("icons\mark_of_din.png"); imgnayru = new imageicon("icons\mark_of_nayru.png"); imgfarore = new imageicon("icons\mark_of_farore.png");

how can modify code display them within jar file?

you should using

new imageicon(getclass().getresource("/mark_of_din.png"));

that little bundle icon in icons folder icon, means files in icons folder @ root of classpath. getclass() gets calling class, , getresource() locates resource relative class. / brings search root.

you can extract jar , see icons folder not there.

see related post

"while works fine in eclipse.."

that's because when pass string imageicon constructor, looking file on file system, relative working directory. in eclipse (and ides), default working directory project root, , that's icons folder is.

java eclipse image jar

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -