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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:07:54+00:00 2026-06-11T13:07:54+00:00

I am trying to open a text file in a frame using JEditorPane (in

  • 0

I am trying to open a text file in a frame using JEditorPane (in an non-editable mode). However, I believe I am having problems with setting up my input stream and output stream. Kindly, look at my code and tell where I am doing wrong.


import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class TextEditor extends JFrame{

private JEditorPane editorpane;
JScrollPane editorScrollPane;
String filename="D:\\abc.txt";
Reader filereader;

public TextEditor()
{       
        editorpane= new JEditorPane();
        editorpane.setEditable(false);

        if (filename != null) 
        {
            try 
            {
                filereader=new FileReader(filename);
                editorpane.setPage(filename);
            }

            catch (IOException e) 
            {
                System.err.println("Attempted to read a bad file " + filename);
            }
         }

        else
        {
            System.err.println("Couldn't find file");
        }

        //Put the editor pane in a scroll pane.
        editorScrollPane = new JScrollPane(editorpane);
            editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        editorScrollPane.setPreferredSize(new Dimension(250, 145));
        editorScrollPane.setMinimumSize(new Dimension(10, 10));

}

public static void main(String[] args) 
{
    TextEditor obj= new TextEditor();
    obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    obj.setSize(600,600);
    obj.setLocation(100,100);
    obj.setVisible(true);
}
}
  • 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-11T13:07:56+00:00Added an answer on June 11, 2026 at 1:07 pm

    To get the argument as a URL for JEditorPane.setPage, you could use:

    File file = new File(filename);
    editorpane.setPage(file.toURI().toURL());
    

    Also don’t forget to add your JEditorPane to the frame so that it can be seen:

    add(editorScrollPane);
    

    To view the disk error you’re getting add:

    e.printStackTrace();
    

    to the IOException block.

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

Sidebar

Related Questions

I am trying to read a text file using Dynamics AX. However, the following
I am trying to open a text file in python. In the following code:
I m trying to open up a text file and look for string Num_row_lables
I am trying to configure my text file viewer to open files by dragging
I'm trying to open a zip file with jython using FileInputStream and ZipInputStream. But
I'm trying to write text to a local file (i.e. on my laptop) using
I am trying to populate combo boxes from a text file using comma as
so I'm trying to open a text file with a poem and see how
My application is trying to open a text file, and is presented with a
I am trying to open a small text file to test some NSFileHandle functions

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.