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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:12:22+00:00 2026-06-04T11:12:22+00:00

In my function for displaying text in textarea,i have written following lines of code

  • 0

In my function for displaying text in textarea,i have written following lines of code but it is not displaying any text

        jTextArea1.setText( Packet +"\n" +jTextArea1.getText());

I am using swingworker for performing background task,here is my code

public class SaveTraffic extends SwingWorker<Void, Void> {


public GUI f = new GUI();

@Override
public Void doInBackground() throws IOException {
              //some code
              sendPacket(captor.getPacket().toString()); 
              return null;
             }//end main function

@Override
public void done() {
    System.out.println("I am DONE");

}


public void sendPacket(String Packet) {

 f.showPackets(Packet);
}

}

and the following lines of code i have written in my GUI form

 public  void showPackets(String Packet) {

 jTextArea1.append( Packet);

}

Solution:
public class SaveTraffic extends SwingWorker {

     public GUI f = new GUI();

     @Override
    public Void doInBackground() throws IOException {
    f.add(jTextPane1);
   // some code

   publish(captor.getPacket().toString());

   // the method below is calling sendPacket on the background thread
   // which then calls showPackets on the background thread
   // which then appends text into the JTextArea on the background thread
  //sendPacket(captor.getPacket().toString());

    return null;
   }

  @Override
   protected void process(List<String> chunks) {
   for (String text : chunks) {
     jTextPane1.setText(text);
     f.showPackets(text);
   }
  }

  @Override
  public void done() {
   System.out.println("I am DONE");

   }

}

  • 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-04T11:12:24+00:00Added an answer on June 4, 2026 at 11:12 am

    Yours is a very incomplete question, one without enough information to allow an answer, and one that forces us to guess, but based on this line in your original post:

    The function is called continuously …

    I’ll guess, and I will bet money that you’ve got a Swing threading issue. You will probably want to read up on and use a SwingWorker.

    Start here to learn about the EDT and SwingWorkers: Concurrency in Swing.

    Yes, yours is a Swing concurrency issue caused by your making Swing calls from within the background thread. To avoid doing this, you need to export the data from doInBackground and call it on the Swing event thread. One way to to do this is via the publish/process method pair:

    public class SaveTraffic extends SwingWorker<Void, String> {
    
      public GUI f = new GUI();
    
      @Override
      public Void doInBackground() throws IOException {
    
         // some code
    
         publish(captor.getPacket().toString());
    
         // the method below is calling sendPacket on the background thread
         // which then calls showPackets on the background thread
         // which then appends text into the JTextArea on the background thread
         //sendPacket(captor.getPacket().toString());
    
         return null;
      }
    
      @Override
      protected void process(List<String> packetTextList) {
         for (String packetText : packetTextList) {
            sendPacket(packetText); //edit, changed to match your code
         }
      }
    
      @Override
      public void done() {
         System.out.println("I am DONE");
    
      }
    
      public void sendPacket(String Packet) {
    
         f.showPackets(Packet);
      }
    }
    

    Check the tutorial I linked to above and the SwingWorker API for more details on this.

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

Sidebar

Related Questions

I have written an SWT UI which has a primary function of displaying text
I have the following script: <script type=text/javascript> $(document).ready(function(){ document.write(<script type=\text/javascript\ src=\http://site.com/script.js\><\/script>); }); </script> When
I need a function to return a suffix for days when displaying text like
I'm having a problem displaying data from a function to text box within a
I need to make some part of text bold while displaying in jquery: $(':checked').each(function()
I have a PHP-script displaying random text: <?php $quotes = array( 'quote 1', 'quote
Is there function for displaying text in R window ? and how to display
The content of the text file is not displaying in the div tag <!DOCTYPE
I've just wrote some code (and it works) for displaying some text near the
I have a RichTextBox displaying a FlowDocument that is large (>10k lines). I am

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.