Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7074791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:06:01+00:00 2026-05-28T06:06:01+00:00

I have two questions for Icons. I am using ImageIcons as default Icons on

  • 0

I have two questions for Icons.

I am using ImageIcons as default Icons on JTree. As suggested by tutorials I am loading icons using this method :

protected ImageIcon createImageIcon(String path) {

        java.net.URL imgURL = getClass().getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
}

Although in order for this to work I have to store the images inside the file with the source code which I believe is messy (but I read its needed for running on .jar). Is there a way to load images similarly while they are on the project folder and not on src ?

Also is there a way to automatically scale images on the correct size for displaying on JTree? Thanks !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:06:02+00:00Added an answer on May 28, 2026 at 6:06 am

    The code doesn’t load the ImageIcon from the src folder. It loads it from the runtime classpath. And for the images to be in the runtime classpath, the easiest way is indeed to place them in the src folder, so that your IDE automatically copies them to the target folder, along with the .class files.

    If you want, you may define another source directory (named resources, for example) in your project, and the IDE will also copy the files of this source directory to the target folder. This allows separating Java files from resource files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two questions. Before detailing these questions, I want to add I'm using
I have two questions here. How can I show the header of the pop
I have two questions. How can I get the spinner in the figure below
I have two questions. Does it make sense when I have to choice of
I have two questions. Question1: How can we add a reference to a third-party
I have two questions. I know it is possible to declare class objects in
I have two questions. I want to send SMSes from a web-site in PHP
I have two questions in regards to the PyDev (Python editor for Eclipse) and
I have two questions: 1) I have a few global variables for my website
I have two questions: (1) I learned somewhere that -O3 is not recommended with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.