This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to update a jtextpane from a thread

 
david luis
Ranch Hand
Posts: 53
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
david luis
Ranch Hand
Posts: 53
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
But... I can declare other time the jlabel to can use it?
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't understand what you are trying to say.
 
m Korbel
Ranch Hand
Posts: 174
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- 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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic