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 8738433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:43:52+00:00 2026-06-13T10:43:52+00:00

When creating an ImageIcon in Java, is there a way to shorten the path

  • 0

When creating an ImageIcon in Java, is there a way to shorten the path to the file instead of having C:\Users\John\Documents\Images\image.gif could I just have the path be image.gif?

I have tried putting the image in the same directory as the Java class but it does not locate the image.

  • 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-06-13T10:43:53+00:00Added an answer on June 13, 2026 at 10:43 am

    ImageIcon ii = new ImageIcon(Test.class.getResource("test.gif"));

    In this case, Test.class and test.gif are in the same location. Normally, you would structure it like so:

    • src/com/mywebsite/Test.java
    • resources/com/mywebsite/test.gif

    Set both src and resources as source folders. Then when you compile, test.gif will be outputted to the same location as Test.class.

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

Sidebar

Related Questions

In my Java Spring web app I am creating an image file. This file
I have a image file stored at a remote server (i.e http://example.com/images).The images in
I am setting image to Label and before that I am creating ImageIcon Object
I am having difficulty creating the image icon. I want to package a jar
Error creating bean with name 'sessionFactory' defined in class path resource [ApplicationContext.xml]: Invocation of
hi friends I am creating a software in java swing where i want to
I am creating a JButton which includes a specific ImageIcon. The main issue is
I use the following program for creating JTable using java class. If I get
I am reading a file as follows: File imgLoc = new File("Player.gif"); BufferedImage image
Hi I have created a PDF file with an image in it, I want

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.