Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes Text Area not getting updated with the button action performed event Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Text Area not getting updated with the button action performed event" Watch "Text Area not getting updated with the button action performed event" New topic
Author

Text Area not getting updated with the button action performed event

Prem Swaroop
Greenhorn

Joined: Apr 11, 2012
Posts: 8
I have created a Text Area where I want to display some lines frequently as soon as the button is clicked. But the problem is that the Text Area is updated only once after the button action performed event is completed. Below is the way I used to display some text :-

private void buttonconnectActionPerformed(java.awt.event.ActionEvent evt){
Some code...
jTextArea1.append("Creating download and upload script in local drive...\n");
jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
Some code...
jTextArea1.append("Files created\n");
jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
Some code...
}

The whole program is creating, uploading, downloading some files to another server. So, that takes some time to complete. I want this text area to display the lines as the code progresses inside the button event.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4165
    
    3

Hello Prem, and welcome to the Ranch!

You need to go through the tutorial on Concurrency in Swing.


luck, db
There are no new questions, but there may be new answers.
Prem Swaroop
Greenhorn

Joined: Apr 11, 2012
Posts: 8
Thanks Darryl for your reply. With the help of SwingWorker, my problem is solved. But still I have one doubt. First I tried to append TextArea in the process() method by the frequent calls to publish() method in the doInBackground() method. Below is the code how I tried first :-

But this did not work. The TextArea did not display anything. As far as I understood from the concept of SwingWorker is that the 2nd arguement is used for returning intermediate results. Can you please explain why it did not work.

Then I did this without publish() and process() method i.e appended TextArea directly inside doInBackground method().
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

You didn't override process, you overloaded it. The correct method signature for your class is protected void process(List<String> chunks). This method takes a List because it's possible that you call publish several times before process is called. So fix the parameter type, then loop through the List to add all chunks.

Also, can you please UseCodeTags next time? Thanks.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 922
    
    2

Rob Spoor wrote:You didn't override process, you overloaded it.


this is one place where the usage of @Override annotation would have helped you find the problem rightaway.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Text Area not getting updated with the button action performed event
 
Similar Threads
JTextArea
For Each Loop
scroll bar for text area
Scroll panel problems
replace a word in the JTextPane without selecting it