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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:56:39+00:00 2026-05-27T13:56:39+00:00

I am trying to access some images for from image panel using a relative

  • 0

I am trying to access some images for from image panel using a relative path. In the Eclipse project I have a folder named images with on image inside. Here is my code:

  val top = new MainFrame {

    title = "Predator and Prey Agent simulation"

    val buttonExit = new Button {
      text = "Exit"
      action = Action("Exit") {
        WorldActor.run(false)
        closer
      }
    }

    val buttonStart = new Button {
      text = "Start"
      action = Action("Start") {
        switchPanes()
      }
    }

    val s = new Dimension(500, 700)

    contents = new ImagePanel(0, 1) {
      for (i <- 0 until 5){
        contents+= new Label("")
      }
      contents += buttonStart
      contents += buttonExit
      contents+= new Label("")

      minimumSize = s
      maximumSize = s
      preferredSize = s
      imagePath = ("\\PredatorPrey\\images\\gnp-canadian-lynx-kitten.jpg")

      }
    }

Every time the above code runs I get a javax.imageio.IIOException. Here is the imapePanel class:

case class ImagePanel(rows0: Int, cols0: Int) extends GridPanel(rows0, cols0) {
  private var _imagePath = ""
  private var bufferedImage: BufferedImage = null

  def imagePath = _imagePath

  def imagePath_=(value: String) {
    _imagePath = value
    bufferedImage = ImageIO.read(new File(_imagePath))
  }

  override def paintComponent(g: Graphics2D) = {
    if (null != bufferedImage) g.drawImage(bufferedImage, 0, 0, null)
    }
  }

Does anyone know how to fix that path?

  • 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-27T13:56:40+00:00Added an answer on May 27, 2026 at 1:56 pm

    i just use awt:

    import java.awt.Toolkit
    val image = Toolkit.getDefaultToolkit.createImage("images/kitten.jpg")
    

    EDIT:

    Also, remove \\PredatorPrey\\ from the image path.

    EDIT 2:
    Just explaining what was wrong with the code as cited in the question – when a file path name starts with “/” (or “\” in windows), it becomes absolute ( slash represents the root of the current file system/ drive). Also, the code included the project name in the path. Since the application is run from inside the project, the project directory is not needed in the path (you are already inside that directory!).

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

Sidebar

Related Questions

I'm trying to transfer some data from Access to SQL Server 2000 (there are
I am trying to access Outlook 2007 from C#. I have installed the PIA
I'm trying to add some functionality from a plugin I have made into a
I'm trying to do some image processing on iPhone. I'm using http://developer.apple.com/library/ios/#qa/qa2010/qa1702.html to capture
I'm using Codeigniter 2. I'm trying to display some images using the background url
I'm trying to copy some binary data from my IStream instance (since Gdiplus::Image only
I have some images on my server folder and I would like to know
How delphi7 access C# .net managed dll ? i'm trying to access some DLL
I am trying to use Python's ctypes library to access some methods in the
I am trying to create a function that will block access to some of

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.