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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:12:58+00:00 2026-06-03T08:12:58+00:00

I have a GUI application that process some data, it converts line of text

  • 0

I have a GUI application that process some data, it converts line of text to an object. Each object that is created is shown on a JTextPane ot JTextArea. example:

Line # 1 created 827401830
Line # 2 created 827401831

So the user is inform of the process.

Behind the scene, there’s a thread that runs in the background and does all the work. The problem is that one of the fields of this thread has is a JTextArea. and it looks like this:

public class ConsumerThread implements Runnable 
{
    private ArrayBlockingQueue<TicketExchangeLine> queue;
    private JTextArea textArea; 

public ExchConsumerThread(ArrayBlockingQueue<TicketExchangeLine> queue, JTextArea textArea) 
{
    this.queue = queue;
    this.textArea = textArea; 
}

public void run() 
{
    try
    {       
        while (true)
        {               
            // check if end of file from producer POV
            if (queue.peek()!=null && ...)
                break;

            MyObject obj = queue.take();

            try{
                //do the process here
                textArea.append("here comes the output for the user..."+obj.getID);

            }catch(Exception nfe)
            {
                //Oops  
            } 
        }

        textArea.append("\nDone!");

    }catch (InterruptedException e)
    {
        // Oops
    }catch(Exception exp)
    {
        exp.printStackTrace();
    }
}

}

So the code above works fine and does the job but sometimes I’m using this thread not from the GUI and then I’m instantiating a JTextArea for no reason; and even worse, I have to system.out everything to see the process.

Question: how can I log all the ‘processed data’ to the JTextArea (or sometime JTextPane) without using the Swing components in the thread?

Thanks!

  • 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-03T08:13:00+00:00Added an answer on June 3, 2026 at 8:13 am

    Instead of passing a JTextArea, pass an OutputStream (e.g. a PrintStream) as parameter. This provides enough flexibility:

    • Your thread just writes to the outputstream
    • If you want the output to appear in a JTextArea, you pass an outputstream which will append the output to a JTextArea. The writing to the text area should happen on the EDT, but the outputstream takes care of this. Your thread is unaware of this
    • If you want to pipe the output to the System.out, you just pass the System.out directly as a parameter
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a command line application that could benefit from a GUI. We want
I'm looking into developing an application that will process data from a line-scan camera
I have a Windows GUI application that's using the Qt framework (currently version 3.3.5,
Suppose I have a GUI-only application that runs on Windows and I'd like to
I have a GUI C++ application (Visual Studio 2008) that needs to be converted
I have a GUI application which works with point cloud data and a quadtree
I have a C++ Win32 application that was written as a Windows GUI project,
I'm building from scratch a web application that is not trivial (have some algorithms
I have an windows service application where I have an object that is processed
I have a WPF application that executes external programs to process media files, and

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.