|
-
July 6th, 2012, 06:01 PM
#1
writing to JTextArea from another object
Hi, Java Eclipse windows
I have a calling class and a class that converts a file. I want to call the file converting class and do a conversion. While thats happening I want to print a number indicating progress in the jTextArea of the calling class...so
Code:
class Object 1 {
public void actionPerformed(ActionEvent e)
{
InnerObject.doStuff(OuterFile, txtArea);
}
}
public static File doStuff(File InnerFile, JTextArea InnerTextArea)
{
try {
while (somecondition) {
//Do converting stuff here
convertstepcounter2=convertstepcounter;
Integer.toString(convertstepcounter2);
InnerTextArea.append(""+convertstepcounter2 + "\n");
InnerTextArea.setCaretPosition(InnerTextArea.getText().length());
convertstepcounter++;
}
}
catch(IOException ie){
ie.printStackTrace();
}
return convertedFile;
}
I get nothing, probably since you have to exit the while loop to print a message. Would there be a solution to this problem so I can get a counting txtArea while in InnerObject?
Thanks
-
July 8th, 2012, 05:10 AM
#2
Re: writing to JTextArea from another object
It's probably not updating the text area until the method returns because Swing is single threaded and I guess you are running the method on the Event Queue Dispatch thread.
When performing this sort of task you should use a javax.swing.SwingWorker. The API docs have usage examples alternatively look at the Java tutorials
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|