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

The Archive Base Latest Questions

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

We were assigned to create a simple compiler as a homework that will take

  • 0

We were assigned to create a simple compiler as a homework that will take set of instructions (containing variables, conditions, jumps, etc.) and evaluate them. That’s already done, but I thought I’d make my program little bit more… “shiny”, and add the ability to load instructions from a text file, just for the sake of user comfort; however, it seems that the JTextArea‘s append () method doesn’t seem to really like me, as it does exactly nothing. Here’s the relevant code:

BufferedReader bufferedReader;
File file;
FileDialog fileDialog = new FileDialog (new Frame (), "Open File", FileDialog.LOAD);
String line;

fileDialog.setVisible (true);

if (fileDialog.getFile () != null) {
    file = new File (fileDialog.getDirectory () + fileDialog.getFile ());
    input.setText (""); // delete old first

    try {
        bufferedReader = new BufferedReader (new FileReader (file));
        line = bufferedReader.readLine ();

        while (line != null) {
            input.append (line);
            System.out.println (line);
            line = bufferedReader.readLine ();
        }
    } catch (IOException ioe) {
        ioe.printStackTrace ();
    }
}

(I’m using Awt’s FileDialog instead of Swing’s JFileChooser because it simply looks better on Mac, as seen in Apple’s official recommendation.)

The input variable used in this code points to the JTextArea instance. The funny thing is – the file reading part must be working flawlessly, as I can see the file content being written to the standard output thanks to the System.out.println () call within the while loop. However, nothing appears in the JTextArea, and I’ve tried all the existing solutions I’ve found here on StackOverflow – that includes calling the repaint (), revalidate () and updateUI () methods.

What am I missing?

  • 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-13T07:36:53+00:00Added an answer on June 13, 2026 at 7:36 am

    The code probably is called on the event handling loop, where you cannot have drawing.
    One would normally use

    final String line = bufferedReader.relineadLine();
    // final+local var so usable in Runnable.
    
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            input.append(line + "\n");
        }
    } 
    

    Unfortunately it takes some care where to place the invokeLatere (as looping). Better use @AndrewThompson’s solution.

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

Sidebar

Related Questions

I want to create a simple web app that will have a connection from
I was assigned to create an HTML email that uses a sliced image in
I'd like to create a procedure that selects all records that have been assigned
I want to create a simple long polling server in node.js where communication will
For a future project we have been assigned to create a simple concept (inside
I will create a simple floor map guide. I have different FLOORS and the
I am attempting to create a simple language interpreter for a homework assignment in
I've been assigned the project of creating a simple console app. that models brownian
I've been assigned a project to create a file storage service on Google App
the company I work has assigned me the task to create a system to

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.