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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:48:05+00:00 2026-06-13T22:48:05+00:00

So the program I am making uses 2 threads: One for the GUI and

  • 0

So the program I am making uses 2 threads: One for the GUI and one to do the work.

I want updates from the work thread/class to print out on JTextArea in GUI class.
Everything I tried didn’t seem to work. I added lines to print out text on the console right after lines to add text to the JTextArea to make sure it had got to the line but everytime console got text but no changes happened to JTextArea in the GUI.

public static void consoleText(String consoleUpdate){
    GUI.console.append(consoleUpdate);
}

I tried this in the work class but nothing happened.
Anyone know how to fix my problem?

Edit:

MAIN.JAVA

public class main {
public static void main(String[] args) {
    Thread t1 = new Thread(new GUI());
    t1.start();
}

GUI.JAVA

public class GUI extends JFrame implements Runnable{

public static JTextArea console;
private final static String newline = "\n";

public void run(){
    GUI go = new GUI();
    go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    go.setSize(350, 340);
    go.setVisible(true);
}

public GUI(){
setLayout(new FlowLayout());
console = new JTextArea(ConsoleContents, 15, 30);
add(console);
}

WORK.JAVA

...{
consoleText("\nI want this text on the JText Area");
}

public static void consoleText(String consoleUpdate){
    GUI.console.append(consoleUpdate);
}
  • 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-13T22:48:06+00:00Added an answer on June 13, 2026 at 10:48 pm

    First, as has been said, your GUI should only run on the Event dispatch thread.

    As it is written, your GUI class does two things : it’s a frame, and a runnable, and both
    are used completely independently. As a matter of fact, calling “run” on a your GUI object creates another, unrelated GUI object. That’s probably the reason why you see nothing.

    So I suggest making your main the following:

    ... main(...) {
      SwingUtilities.invokeLater(new Runnable() {
          public void run() {
              GUI gui= new GUI();
              gui.setVisible(true); // and other stuff
          }
      });
    }
    

    (I would also suggest getting rid of all “static” fields BTW. It’s probably the source
    of your problems, along with the weird place of the “run” method).

    Now, your “consoleText” method, which I assume you call from another thread, should not
    modify the text directly, but call SwingUtilities.invokeLater() to do so :

    public void consoleText(final String consoleUpdate){
     SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          console.append(consoleUpdate);
        }
     });
    

    }

    (the “final” declaration is important, as it allows the Runnable to use the consoleUpdate variable).

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

Sidebar

Related Questions

I'm making a program on the HUFFMAN ALGORITHM where I have one class of
Im making an application that uses of API-threads in C, The program takes N-files
I'm making a text-based, menu driven program which uses the scanner class to take
I've worked on a program that uses databases to send small messages from one
I am using the cool map making program DIY map and i want to
Im making a program for class that manages a Hotel. I have a function
Working with a program that uses 16bytes 4v4 one byte matrices : unsigned char
I am making a java program that uses the interpolation search below I have
I am making an application which uses a separate program to unzip some files.
I'm making a program that generates a maze and then uses bredth first search

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.