NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
marconi
Joined: 01 May 2012 Posts: 4
|
Posted: Tue May 01, 2012 12:45 pm Post subject: ProgressHandler not updating while TopComponent working |
|
|
hello!
In topcomponent I have a button which retrieves data from DB and displays it in jtable. it can take a while, so I`ve added a dummy progreshandle in a swing worker before data retrieve. but GUI doesnt display the progreshandle while data retrieving.
after data has been downloaded progress handle suddenly appears with 30% completion and goes to 100% as it should (so it was running in a sepate thread in background from 0-30% but I was not displayed on statusbar).
| Code: |
new SwingWorker<Object, Object>()
{
@Override
protected Object doInBackground() throws Exception
{
ProgressHandle handle = ProgressHandleFactory.createHandle("......");
handle.start(1000);
//handler should be switchtointerdeterminate but for testing purposes I`ve added dummy progress 0-100%
for (int i = 1; i <= 1000; i++)
{
handle.progress(i);
Thread.sleep(20);
}
handle.finish();
return null;
}
}.execute();
|
Before swing worker I tried Runnable but effect was the same. what am I doing wrong?  |
|
| Back to top |
|
 |
bruehlicke
Joined: 18 Sep 2009 Posts: 154
|
Posted: Wed May 02, 2012 10:20 pm Post subject: [platform-dev] Re: ProgressHandler not updating while TopComponent working |
|
|
You should have the data access code doing the data base retrieval as well in the swingworker than there is no need to have any dummy code waiting. On May 1, 2012 6:25 PM, "marconi" <address-removed ([email]address-removed[/email])> wrote: | Quote: | hello!
In topcomponent I have a button which retrieves data from DB and displays it in jtable. |
|
| Back to top |
|
 |
marconi
Joined: 01 May 2012 Posts: 4
|
Posted: Wed May 02, 2012 10:38 pm Post subject: Re: [platform-dev] Re: ProgressHandler not updating while TopComponent working |
|
|
[quote="bruehlicke"]You should have the data access code doing the data base retrieval as well in the swingworker than there is no need to have any dummy code waiting. On May 1, 2012 6:25 PM, "marconi" <address-removed ([email]address-removed[/email])> wrote: | Quote: | hello!
In topcomponent I have a button which retrieves data from DB and displays it in jtable. |
yep, it worked like a charm! thank you! |
|
| Back to top |
|
 |
Posted via mailing list.
|
Posted: Thu May 03, 2012 4:31 am Post subject: [platform-dev] Re: ProgressHandler not updating while TopComponent working |
|
|
| I had the same issue on any test example. The problem was |
|
| Back to top |
|
 |
marconi
Joined: 01 May 2012 Posts: 4
|
Posted: Thu May 03, 2012 9:48 am Post subject: Re: [platform-dev] Re: ProgressHandler not updating while TopComponent working |
|
|
| Anonymous wrote: | | I had the same issue on any test example. The problem was |
is it possible then to add just one swingworker, runnable, callable or any type of threading to database class so that any query connection would have and progress bar? (that was my initial approach)
because in this case I would have to add to every method in gui that uses db a swing worker, and I would rather avoid that. amount of work to achieve this is enormous....(~300 db methods) |
|
| Back to top |
|
 |
Posted via mailing list.
|
Posted: Fri May 04, 2012 4:20 am Post subject: [platform-dev] Re: ProgressHandler not updating while TopComponent working |
|
|
In such case you can write some wrapper class for Runnable that will call progress ui.
2012/5/3 marconi <address-removed ([email]address-removed[/email])>
| Quote: |
Anonymous wrote:
| Quote: | I had the same issue on any test example. The problem was
|
is it possible then to add just one swingworker, runnable, callable or any type of threading to database class so that any query connection would have and progress bar? (that was my initial approach)
because in this case I would have to add to every method in gui that uses db a swing worker, and I would rather avoid that. amount of work to achieve this is enormous....(~300 db methods)
|
|
|
| Back to top |
|
 |
marconi
Joined: 01 May 2012 Posts: 4
|
Posted: Mon May 07, 2012 1:42 pm Post subject: issue solved |
|
|
wrapping DB class with runnable didnt help but I did manage.
I had to create a thread on the bottom DB class and added it to EDT (event dispatch thread - responsible for GUI) by:
Runnable doWorkRunnable = new Runnable() {
public void run() { doWork(); }
};
SwingUtilities.invokeLater(doWorkRunnable);
Works perfect.
thanks for the tips. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|