How Do I get icons image directory to work in a JAR file?

Yes, I must admit after going through the tutorial and other stuff I am stiil stumped
I have an application that uses the jlfgr icons for the toolbar, and it works fine as long as i actually run it from the directory that it is in.
I would like to put in into a jAr file, and be able to execute it from other places.
I have a Directory named PhoneBook
in that are the classes I use
AddressBook - the main class
PersonEntry - The 'data class'
and various other things like FileFilters.....
inside that directory there are two more:
images - contains all the icon images
Data - where the default 'database' entries are stored.
I use code like this:
     private void fillToolBar( JToolBar bar )
          Dummy = new JButton(new ImageIcon("images/New16.gif"));
          Dummy.setActionCommand("New");
          Dummy.addActionListener(this);
          Dummy.setToolTipText("New");
          bar.add( Dummy );
          // etc etc
to get all the icons into the toolbar
I have made a Jar file that has all the classes and all the directorys with the icons in it
and so the program runs, but does not get the icons for the toolbar, I just get a whole load of 'dud' buttons.....
AS this is the first time i've ever got the GUI to look right rather than just the code functioning properly
I'd like to get the whole thing in a working Jar file
So Could someone show me Step By Step, How I get my classes and images into a Jar file
so that i can from a different directory go
java - jar Phone.jar
and have the GUI come up with all the images, assuming I'm totally thickheaded when it comes to Jar files.?
I also can't get the images to show up if I merely run the 'program' from another directory than the one it is compiled in
I can get the program to run, just not access the images with something like
java -cp blah/blah/blah AddressBook
{the main class is AddressBook }
the data directory can be anywhere as I use a JFileChooser to allow the user to open and save desired files.
I really would appreciate some clear workable help. {though I'm running out of Duke Dollars...}

What you need is a correct path to the directory
inside of the jar. This can be accomplished by adding
a line to your main program like this:
URL
url=myProgram.class.getResource("images/New16.gif");
Dummy = new JButton(new ImageIcon(URL));
where myProgram.class is the name of the class
file that contain the main method.
Hope this helps....
;o)
PS: I don't want your dukes...I got them coming out of
my ears!
O.K, that works thank you.
I put something like:
for all the 'buttons' in the toolbar
URL url = null;
Class ThisClass = this.getClass();
url=ThisClass.getResource("images/New16.gif");
Dummy = new JButton(new ImageIcon(url));
Dummy.setActionCommand("New");
Dummy.addActionListener(this);
Dummy.setToolTipText("New Database");
bar.add( Dummy );
etc for all the rest of the 'buttons'
After Reading the API docs on URL's etc I'm still not sure as to why it works, but it does....
I am able now to place the class files in a jar along with the images and it all works fine
although now I don't quite follow all my code....................
I assume that
url=ThisClass.getResource("images/New16.gif");
returns some sort of 'relative url ' ???
Thanks for the help though.

Similar Messages

  • If I add artwork by dragging a jpg to the artwork area after selecting several rows, in some instances a single icon is created in the flipper;  in others one is created for each song. Why? How can I get one image per album every time?

    If I add artwork by dragging a jpg to the artwork area after selecting several rows, in some instances a single icon is created in the flipper;  in others one is created for each song. Why? How can I get one image per album every time?

    If I add artwork by dragging a jpg to the artwork area after selecting several rows, in some instances a single icon is created in the flipper;  in others one is created for each song. Why? How can I get one image per album every time?

  • How to make an icon image using Photoshop

    I found out how to do this recently so I decided that I wanted to make a tut for those who don't know how to make an icon image. This icon image is for the libraries tab on your computer. Under the libararies tab there is Music, Pictures, Documents, and Photos
    First you will need the ICO (Icon image format) Format extension for photoshop which can be downloaded here:
    http://www.telegraphics.com.au/svn/icoformat/trunk/dist/README.html
    The download link and tutorial on how to install it is all in the link above.
    Once you have that all set you can now launch photoshop to create your icon image. Once you have launched it, create a new document with the size as in the image below.
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/256x256_zpsbf3dcf8e.png~original[/IMG]
    Create the image you want. I used a simple one by using the custom shape tool by pressing "U" on your keyboard and with the
    basic blending options.
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/IconImage_zpsd788c709.png~original[/IMG]
    The reason why the image is pixelated is because it is an icon image. Since the image is only 256x256 pixels when you zoom in on it that will get you the pixely result. The reason why I zoomed  in is so you can see it. But don't worry this is no the end result. Just continue reading and you will see.
    So once you have created the icon go ahead and press
    file>save as>(under format choose the ICO)>and choose the name that you want to name it. And save it in your C: drive. You will see why to save it in your C: drive in a sec.
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/SampleicoPic_zpsd252bfba.png~original[/IMG]
    So now that you have created the icon and saved it now you can create the new library.
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/NewLibrary_zps8ca703b2.png~original[/IMG]
    Name the library whatever you want I named it "Sample" for tutorial purposes. Notice how it gives you a default boring icon image for your library.
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/Sample1_zpsb5472840.png~original[/IMG]
    So now once you have created and named your library now it is time to get the icon image into place.
    Go to computer/c: Drive/users/YOU/ And now once you have reached this area you will need to access a hidden folder named "appdata" to do so press "Alt" then a menu bar will show. Click
    tools>folder options>and view. Find the option to view hidden folders then press apply then ok. Now we shall continue so AppData>Roaming>Microsoft>Windows>Libraries
    Now you should see all the libraries including the one you just created.
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/showhiddenfolder_zpsad4a3c94.png~orig inal[/IMG]
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/Libraries_zpsf6243bc0.png~original[/IMG]
    Once you have reached your destination then open a new text document with notepad and drag the library you just created in notepad. The result should look like this:
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/Notepad_zps251a86f0.png~original[/IMG]
    once you have reached this point click at the end of the second to last line down then press enter and enter in this information
    <iconReference>c:\"NAME OF ICO FILE YOU CREATED IN PS".ico</iconReference>
    Example:
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/iconreference_zps1c1a3eca.png~origina l[/IMG]
    Once you have entered that information go to file>save and the icon image should appear on the library you created.
    [IMG]http://i1297.photobucket.com/albums/ag25/dusty951512/Finished_zps267f893a.png~original[/IMG]
    Now you are officially finished. Go and spread the news and joy. Bye for now
    -Dusty951512

    It is Windows only because all those screen shots are exclusively Windows, the file structure and paths do not resemble those of the Mac in the least.  As a Mac user, there's nothing I could take from your tutorial.  Sorry, 
    No drives named with letters like C: on the Mac, for instance.  No backward slashes either, ever.  No such paths either.  No "Notepad" on the Mac, we use TextEdit; but such a text editor is not remotely needed on the Mac to make and/or edit icons.  Etc.
    Those folders are not even called "Libraries" on the Mac…  Nothing resembling your tutorial at all.
    The icons in the Finder's Sidebar are not customizable at all in recent version of OS X.
    =  =  =
    You can edit any post of yours only until someone replies to it.  At this time your post is not editable by you any longer.

  • How to set folder icon image in OS X Lion?

    I set my folder's icon image in OS X Leopard before, but I don't know how to do that in Lion.  In Leopard you simply copy the icon image from an Info window of a file, and paste that into the folder's icon image in the top left corner of its Info window.  In Lion I don't see the icon of the file in its Info window as a preview, but rather I see only a generic JPG file icon.  Any ideas?

    Can you explain why there was no thumbnail for that file?
    The OS does not create or add thumbnails, previews, nor custom icons to images or other files. Although it displays files with what appears to be a custom icon, it is not part of the file itself; it is created on the fly, just for display. Since it is not part of the file, it does not appear in the Get Info window.
    Back in OS 9 days when you downloaded an image file from the web, either via drag and drop or via the download mechanism, the image file would typically be placed on the drive as a QuickTime image with both a custom icon and a preview image added to it.
    I skipped earlier versions of OS X, and started with Snow Leopard, so don't know about earlier versions of OS X. Apparently the auto creation and addition of a custom icon and preview have been dropped in later versions in favor of using Preview to generate a temporary (for display only) custom icon on the fly. One result of this is that image file sizes are kept reasonably small - adding a suite of custom icons and a preview image to the file itself increases the file size a lot; it's not unusual for those additions to double the file size, or more.

  • How do I get icons to show up on my iphone

    Before upgrading to IOS7, I had more icons showing. Missing several; when I search and type the name in, apps open up. How do I get icons to "reappear" on my phone?

    1)  Check in All Folders and on All Pages/Screens...
    2)  If no joy...
    Settings > General > Reset > Reset Home Screen
    3)  Also... Check in Restrictions... Settings > General > Restrictions
    Understanding Restrictions  >  http://support.apple.com/kb/HT4213

  • How can we get the image which is stored in clipboard by labview, is there any functions available like text from clip board

    How can we get the image which is stored in clipboard by labview, i can get the text in clipboard by using invoke node directly.but i cannot get the image, is there any functions or vi available.(image is in Png format)

    The Read from Clipboard method is, unfortunately, limited to text. If the clipboard contains an image then you need to use OS-specific functions calls. This is an example program for Windows. It's old, but it should still work.

  • How can I get an image from the screen? Like screen printer in PC to pasting after in word or other program.

    How can I get an image from the screen? Like screen printer in PC to pasting after in word or other program.

    If you do Cmd+Shift+3 you'll get a full screen image saved to your desktop as a jpg file.
    Also, you can use Cmd+Shift+4 and you'll get a cursor which you click+drag to draw a box. When you release the drag the boxed in area will be saved to the Desktop as a jpg file.

  • How do I get an image next to my link on facebook or linkedin?

    How do I get an image next to my link on facebook or linkedin?
    Cheers, Joakim

    Make sure there are images on your page.

  • When editing an image in Photoshop from Lightroom then saving it back to Lightroom, how do i get the image to go back and  sit next to the original? Mine is going to the end of the folder. Thanks Karen

    When editing an image in Photoshop from Lightroom then saving it back to Lightroom, how do i get the image to go back and sit next to the original image? Mine is going back to the end of the folder. Thanks Karen

    Hi Karen
    You may the sort set to Custom. Click the dropdown menu on the toolbar (to the right of the word sort) and change to capture time.
    If you can’t see the toolbar above the filmstrip press the T key. Press T again to hide.

  • I am downloading from a Canon 650D to Photoshop CS5.1 AND Adobe Bridge CS5.1  do i need to download a  DNG convertor? if so how do i get the images from the camera to the convertor?

    I am downloading from a Canon 650d  TO Photoshop CS5.1  and Adobe Bridge CS5.1  Do i need to download a DNG convertor? if so how do i get the images from the camera to the convertor?

    Please check the list yourself and co,mare the necessary CR version with the one your version of Photoshop utilizes. 
    If the version os higher than yours you can use the free DNG Converter – as to how to use it please read up on that.
    Camera Raw plug-in | Supported cameras

  • New "Photos" is a piece of JUNK!  How do I get my image numbers to display as imported like they used to? Can no longer make Events or view old events as before either.

    How do I get my image numbers to display as imported like they used to? Can no longer make Events or view old events as before either.
    If this is replacing Aperture and previous iPhoto it is USELESS...WAY fewer options for editing available. New "Photos" is a piece of JUNK!

    Hi.
    I have just migrated my library from Aperture to photos. All seems to have gone smoothly, except for one thing. All of my photos are 'untitled', whereas in both Aperture, and previously iPhoto, the filename was used for the title. If I hit CMD+I and get info, the title is still there as the filename, as I use the filename for all titles.
    Is there a way to batch copy all filenames as photo titles, this was done automatically in Aperture and iPhoto, as when photos were imported the filename was used automatically.
    Any help appreciated.
    Thanks.

  • How can I get Launching report directory in report trigger??

    how can I get Launching report directory in report trigger??
    pls help me :'<
    I can run this function in forms.
    "how can I get Launching report directory in report trigger??"
    does reports have same function???

    Click the little down arrow/+ symbol  next the + - in the folders bar.

  • How can I get the image width and height stored in database?

    Hi!I write s servlet to display images store in database.but how can I get the image width and height?

    Have you tryed using PJA or a similar library?
    I presume you get java.lang.NoClassDefFoundError on the line :
    Toolkit.getDefaultToolkit();?

  • After i reading bytes ,how do i get the image to display?

    After i reading bytes ,how do i get the image to display?
    i m lost after tis step:
    Image img=Toolkit.getDefaultToolkit().createImage(data1);

    You can create and use a Canvas. (and define the Paint method)
    Canvas c = new Canvas(){
            public void paint(Graphics g){
                g.drawImage(img,0,0,this);
    frame.add(c);

  • I accidentally moved my iphoto library to another foler, and i delete the original one, how can i get my images back

    i was thinking of clear some space for my macbook, so i moved some images form picture to window disk, but i accidentally moved iphoto library too. And i didn't realised it would affect iphoto, until i opened iphoto finding all the images were gone. How can i get the images back?

    This might help:  Rebuilding the iPhoto library

Maybe you are looking for