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

  • Home
  • SEARCH
  • 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 3427776
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:52:42+00:00 2026-05-18T06:52:42+00:00

I am creating a Swing application with a JEditorPane that should display an HTML

  • 0

I am creating a Swing application with a JEditorPane that should display an HTML file named url1.html stored locally in the page folder in the root folder of the project.

I have instantiated the following String object

final String pagePath = "./page/";

and in order to be displayed by the JEditorPane pane I have created the following URL object:

URL url1 = new URL("file:///"+pagePath+"url1.html");

However when the setPage() method is called with the created URL object as a parameter:

pagePane.setPage(url1);

it throws me a java.io.FileNotFoundException error.

It seems that there is something wrong with the way url1 has been constructed. Anyone knows a solution to this problem?

  • 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-18T06:52:43+00:00Added an answer on May 18, 2026 at 6:52 am

    The solution is to find an absolute path to url1.html make an object of java.io.File on it, and then use toURI().toURL() combination:

    URL url1 = (new java.io.File(absolutePathToHTMLFile)).toURI().toURL();
    

    Assuming if the current directory is the root of page, you can pass a relative path to File:

    URL url1 = (new java.io.File("page/url1.html")).toURI().toURL();
    

    or

    URL url1 = (new java.io.File(new java.io.File("page"), "url1.html")).toURI().toURL();
    

    But this will depend on where you run the application from. I would make it taking the root directory as a command-line argument if it is the only configurable option for the app, or from a configuration file, if it has one.

    The another solution is to put the html file as a resource into the jar file of your application.

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

Sidebar

Related Questions

I've creating a Java Swing application and I realized that I have many many
In my Swing application I have the problem that when creating a new instance
I'm creating a Swing application that connects to a web server, running some servlets
I'm new to Java and Java Swing, and I'm creating an application that requires
I'm creating an java application on a Mac that uses Swing JMenu s. I
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
I am creating my java Swing application in Netbeans. At present there are more
I need a Swing component that will let me display a tree-structured list of
I need some advice on creating a syntax highligher for java application using swing.
I'm developing an application that features multiple Swing GUIs. The main GUI has a

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.