Getting a icon from jar or system directory

Posted on 2006-05-28
Last Modified: 2010-03-31
ImageIcon icon = new ImageIcon(iconPath) is the way I use to gat an icon from a system folder, assuming that iconPath maybe something like "icons//myicon.gif" relative to the root path of application. It works, but when I embedd the icons dir in a jar an try to get it as resource I'm unable to get as system file or the contraty....
Question by:rubentrancoso
    LVL 86

    Accepted Solution

    I would put an


    entry at the root of your jar. You can then do

    ImageIcon icon = new ImageIcon(getClass().getResource("/images/myicon.gif"));


    Author Comment

    LVL 86

    Expert Comment


    A suggestion:

    "Creating bar/popup menus was never so easy and elegant. From a simple XML file with bar/popup menu definitions and a line of code it's possible to build full menus with all the functionality these components ever need to have."

    Author Comment

    right! :)

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    scoresIncreasing challenge 10 48
    how to use external config file with Spring MVC 4 38
    countX 22 50
    Updating Java 9 62
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    This video teaches viewers about errors in exception handling.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now