Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Paul Clapham wrote:Yes, that's exactly right. But unfortunately it's a bit more complicated than just running the update in a separate thread. So read the tutorial: Lesson: Concurrency in Swing.
Jelle Klap wrote:Don't perform the save operation on the Event Dispatch Thread, but use a SwingWorker to spin-off a new worker thread to perform the save operation instead. Have a look at this tutorial.
Edit: Aaaaaw, I almost made it...
Paul Clapham wrote:I suggest that you imitate what you read in the tutorial. There were examples, weren't there? And did they extend SwingWorker, or did they do something else?
Tony Docherty wrote:The exception is saying the method addPropertyChangeListener takes a parameter that must be assignable to type java.beans.PropertyChangeListener but it has been passed an object of type controller.Controller.generateListener.
In other words the object that 'this' refers to must implement the interface java.beans.PropertyChangeListener.
Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Ranganathan Kaliyur Mannar wrote:You seem to be using PropertyChangeListener for getting interim results. Instead the right way is to use publish-process. In the tutorial that was suggested to you earlier, there is a page with the title "Tasks that Have Interim Results". Here is the link.
Read through that to understand how to do that. Also, in the subsequent pages, you can find a progress bar example.
Horche Gratsias wrote:I have solve it .
Horche Gratsias wrote:
The only question that i have is can i use More than one SwingWorker class for a different works?Is it ok or do i have to use something else? .
Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Ranganathan Kaliyur Mannar wrote:And, I think this discussion fits in our Swing forum (where GUI issues are discussed).
Do you mind if I move it?
Ranganathan Kaliyur Mannar wrote:
Horche Gratsias wrote:I have solve it .
Cool. so, how did you solve it? did you get rid of PropertyChangeListener and used SwingWorker instead (via publish-process) ? we would like to know.
Horche Gratsias wrote:
The only question that i have is can i use More than one SwingWorker class for a different works?Is it ok or do i have to use something else? .
Sure, I don't see any problems with that, though I have myself never tried it.
Ranganathan Kaliyur Mannar wrote:
Horche Gratsias wrote:I have solve it .
Cool. so, how did you solve it? did you get rid of PropertyChangeListener and used SwingWorker instead (via publish-process) ? we would like to know.
Horche Gratsias wrote:
The only question that i have is can i use More than one SwingWorker class for a different works?Is it ok or do i have to use something else? .
Sure, I don't see any problems with that, though I have myself never tried it.
Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Ranganathan Kaliyur Mannar wrote:You can surely use more than one SwingWorker if you think there are different types of tasks to be done and it would be easier to handle it separately. You can also do a series of operations in a single SwingWorker in the doInBackground() method. It really depends on the requirement.
Ranganathan Kaliyur Mannar wrote:You can surely use more than one SwingWorker if you think there are different types of tasks to be done and it would be easier to handle it separately. You can also do a series of operations in a single SwingWorker in the doInBackground() method. It really depends on the requirement.
Edit: My post co-incided with your new post. You don't need to start the worker itself in a separate EventQueue.invokeLater(). This can be done within your GUI classes (the GUI construction itself should be invoked with SwingUtilities.invokeLater).
Moved this discussion to our Swing forum where you will get more replies.
Ranganathan Kaliyur Mannar wrote:You can surely use more than one SwingWorker if you think there are different types of tasks to be done and it would be easier to handle it separately. You can also do a series of operations in a single SwingWorker in the doInBackground() method. It really depends on the requirement.
Edit: My post co-incided with your new post. You don't need to start the worker itself in a separate EventQueue.invokeLater(). This can be done within your GUI classes (the GUI construction itself should be invoked with SwingUtilities.invokeLater).
Moved this discussion to our Swing forum where you will get more replies.
Ranganathan Kaliyur Mannar wrote:You can surely use more than one SwingWorker if you think there are different types of tasks to be done and it would be easier to handle it separately. You can also do a series of operations in a single SwingWorker in the doInBackground() method. It really depends on the requirement.
Edit: My post co-incided with your new post. You don't need to start the worker itself in a separate EventQueue.invokeLater(). This can be done within your GUI classes (the GUI construction itself should be invoked with SwingUtilities.invokeLater).
Moved this discussion to our Swing forum where you will get more replies.
Horche Gratsias wrote:
like what can you give an example ?
how do you seee the code above?
Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Horche Gratsias wrote:Yes i have try that you are right.thanks so the solution was to avoid the property listener
Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Ranganathan Kaliyur Mannar wrote:
Horche Gratsias wrote:Yes i have try that you are right.thanks so the solution was to avoid the property listener
PropertyListener is very useful, but in Swing if you don't want to block the GUI with long operations, you better use SwingWorker and the publish-process model to update the GUI for interim results.
Ranganathan Kaliyur Mannar wrote:
Horche Gratsias wrote:
like what can you give an example ?
how do you seee the code above?
well, in my doInBackground():
So, I do more than one task and also publish my intermediate results by updating the GUI (in this case appending to a JTextArea).
In your code I see lot of sysout statements. I think you can replace them with publish-process and update the GUI.
Horche Gratsias wrote:If i want the doTask@ to start another time ?what can i do for that?
Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
No more fooling around. Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|