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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.