File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to update a jtextpane from a thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to update a jtextpane from a thread" Watch "How to update a jtextpane from a thread" New topic
Author

How to update a jtextpane from a thread

david luis
Ranch Hand

Joined: Mar 10, 2011
Posts: 52
    
    1
Hi,
I've created a jframe with a jtextpane and more controls. I must execute a threat and in these thread I would like to update the jtextpane but it gives an error because the jtexpanel cannot be resolved.

Could you help me please?
Thanks and sorry for my english!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

I recommend that you go through the tutorial on Concurrency in Swing. All Swing methods and constructors should be called on the EDT.

Apart from that, to get better help sooner post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.


luck, db
There are no new questions, but there may be new answers.
david luis
Ranch Hand

Joined: Mar 10, 2011
Posts: 52
    
    1
Darryl Burke wrote:I recommend that you go through the tutorial on Concurrency in Swing. All Swing methods and constructors should be called on the EDT.

Apart from that, to get better help sooner post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.






It says me lblNewLabel cannot be resolved.

Any help?
Thanks
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2410
    
  50
If you want to update a Swing component from a background thread I suggest you look at SwingWorker because as Darryl has already said you need to call Swing methods on the EDT and not from your background thread. SwingWorker provides a mechanism to handle this type of situation.

As for why you are getting the error, it's because lblNewLabel is not declared in your Thread class and you are using it as if it is a local/instance variable.
david luis
Ranch Hand

Joined: Mar 10, 2011
Posts: 52
    
    1
Thanks
But... I can declare other time the jlabel to can use it?
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2410
    
  50
Sorry, I don't understand what you are trying to say.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 157
- change ejecutar.run(); to ejecutar.start();

- use Runnable#Thread instead of plain Thread,

- code snipped notified EDT properly, output from WorkersThread to Swing GUI must be wrapped in invokeLater()

- you can to try that with SwingWorker, but required little bit more knowledges about Java Essential Classes

- rest of them (your issue) is only your issue, as mentioned post an SSCCE demonstrated your issue, short , runnable, compilable, with value from/to WorkerThread will be hardcoded as local variable
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to update a jtextpane from a thread