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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:18:46+00:00 2026-06-03T05:18:46+00:00

I am trying to show a html file in a jeditorpane. The file is

  • 0

I am trying to show a html file in a jeditorpane.

The file is saved in the project folder and was generated by the program. It is a receipt called FredReceipt.html

I understand how to use a jeditorpane for a url, however I have not been able to understand how I can load a file in through the tutorials etc… I have been reading from the web. I want to load the file in using a relative url. This is what I have at the moment, it’s not working (obviously), it’s catching the IOException.

public void showReceipt() {
    receiptPanel = new JPanel();
    receiptPanel.setVisible(true);
    receiptPanel.setBackground(new Color(250,251,253)); 
    String url = "FredReceipt.html";
    try {
      JEditorPane htmlPane = new JEditorPane("FredReceipt.html");
      htmlPane.setEditable(false);
      receiptPanel.add(new JScrollPane(htmlPane));
    } catch(IOException ioe) {
      System.err.println("Error displaying " + url);
    }

}

I have also tried using the ‘setPage()’ method like this:

public void showReceipt() {
    receiptPanel = new JPanel();
    receiptPanel.setVisible(true);
    receiptPanel.setBackground(new Color(250,251,253)); 
    try {
      JEditorPane htmlPane = new JEditorPane();
      htmlPane.setPage(new URL("FredReceipt.html"));
      htmlPane.setEditable(false);
      receiptPanel.add(new JScrollPane(htmlPane));
    } catch(IOException ioe) {
      System.err.println("Error displaying file");
    }

}

FredReceipt.html is obviously not a url, but I have read that files can be read in much the same as urls, I just haven’t been able to find the correct way.

I hope my question isn’t too dumb, thanks a lot!

  • 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-03T05:18:47+00:00Added an answer on June 3, 2026 at 5:18 am

    The file should not be written to the same directory in which the application is installed. Since this data is generated by the application, it seems temporary. In that case, it would be best to put in the java.io.tmpdir, as a temporary file, with a request to delete on exit. Something like this:

    File tempDir = new File(System.getProperty("java.io.tempdir"));
    File receiptFile = File.createTempFile("FredReceipt", "html", tempDir);
    receiptFile.deleteOnExit();
    // fill the file with mark-up
    // ...
    // end filling
    editorPane.setPage(receiptFile.toURI().toURL());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add inline SVG to an HTML file, but it doesn't show
I'm trying to add some jQuery + ERB to a specific view: views/posts/show.html.erb (top
I'm trying to download all png files contained in an html file. I have
In my index.html.erb file I'm trying to display the title to my object (a
I am trying to transform an RDF file to HTML using XSLT. I am
I'm trying to display the html inside of a php file i have. I'm
I have a problem when trying to see a .pdf file (generated with PDFKit)
I have this HTML file with some CSS styles, now I am trying to
Trying to show a label only when a certain item in a combo is
I am trying to show by example that the prefix increment is more efficient

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.