Anton Putov
Anton Putov

Reputation: 1981

Updating JTabbedPane components

I am writing a simple chat program that shows different dialogs in different tabs of a JTabbedPane. I used a JTextArea to display the dialog. I added a JTextArea to the tab like this:

 JTextArea referenceToAppend = new JTextArea();
 JTabbedPane.addTab(title,new JPanel(new JScrollBar(referenceToAppend)));

I put the reference referenceToAppend into a List, then when I need to append text I do the following :

 List.get(index).append(textForAppend);

The problem is: my application becomes unresponsive. How can I solve this problem? I looked up a lot of information on forums and of course, Oracle. I can't find what I need. Maybe I was inattentive or may be I am not understanding something simple. I will be very grateful if someone could give a simple example or link to another forum where they discuss this problem.

Upvotes: 0

Views: 199

Answers (1)

Devon_C_Miller
Devon_C_Miller

Reputation: 16528

Take a look at SwingWorker. It allows you to perform operations in a background thread an report information to the Event Dispatch Thread. If you need to block on a socket read, you need to do that on a background thread to keep the UI responsive.

Upvotes: 1

Related Questions