Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add progressbar to project for listen the swingworker updates

 
Taylan Altay Senturk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a problem with progress bar implementation to my project. Let me explain it;

I have Jframe named GUI. Filled with 2 datechooser combo box and 1 Buton.

And i have a Swingworker class named "MySwingWorker" for my long running task just like this;



My Buton action in GUI just like this;



Just i want add a progress bar for listening MySwingWorker's setProgress updates. When buton clicked swingworker should executed and progress bar should come to screen. I read many articles about that but not understand correctly. Because i am beginner in JAVA.

Question1: Should i (create new class) or (implement to current gui or swingworker class) for progressbar?

Question2: Should i fired progress bar first and execute swingworker from progressbar class? or should i execute swingworker first and fired progress bar later and how?

Thanks in advance.
 
Paul Clapham
Sheriff
Posts: 21581
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start with this tutorial: How to Use Progress Bars. I'm not sure how you would interface your SwingWorker code, but perhaps after you work your way through that tutorial and study the examples included with it you will see how. If not, then by all means come back and ask a follow-up question about your new code.
 
Piet Souris
Rancher
Posts: 1530
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Taylan,

in addition to the documentation about progress bars, in this code from
Oracle you see an example of how to combine it with a SwingWorker.

http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/uiswing/examples/components/ProgressBarDemoProject/src/components/ProgressBarDemo.java

Greetz,
Piet
 
Taylan Altay Senturk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:hi Taylan,

in addition to the documentation about progress bars, in this code from
Oracle you see an example of how to combine it with a SwingWorker.

http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/uiswing/examples/components/ProgressBarDemoProject/src/components/ProgressBarDemo.java

Greetz,
Piet


Hi Piet,

I already check this and below articles thanks for suggestion. But in this article all progress bar attached to Main Gui and Swingworkers not use any GUI variables. In my project, i must use GUI variables for get the dates etc..

If you must use GUI variables in Worker you must create constructor in Worker you know. Just like this;



When i use this constructor in Worker, i can't use Worker instance anywhere. When i write below code in other class i can get error.

So if i use constructor in SwingWorker for get variables from GUI, I can't create any other constructor in any other class for reach to MySwingWorker. And i dont know how i solve it
 
Taylan Altay Senturk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also My GUI looks like below ss;



Just i want when i press GO buton MySwingWorker executed and appearing new progressbar jframe (progressbar may be creating in other class i dont know) Above code work succesfully and return user selected values. But i dont listen "setProgress" command of MySwingWorkers.

I know i must create progressbar and use something like below;



But how ? Should i create new jframe form for progress bar? If yes i can't use MySwingWorker worker1 = new MySwingWorker(); command in new progressbar class because of MySwingWorker constructor.
If no- Where should i create new progress bar jframe ?

Really i am confused about 4-5 days Any comments are welcome.
 
Paul Clapham
Sheriff
Posts: 21581
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's the problem here? Your SwingWorker needs a reference to the ProgressBar so that it can update it? Then just give it that reference. Passing it the reference via the constructor would be the simplest approach.
 
Taylan Altay Senturk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I create new class for progressbar named ProgressBar;

MySwingWorker worker = new MySwingWorker(); line is return error an says;
"constructor MySwingworker in class MyswingWorker cannot be applied to given types;"

EDIT:
I solve this problem define second constructr in MySwingWorker just like this;

and edit my buton action in GUI just like this;

But when i press buton in GUI, progressbar appearing but not updating but MySwingWorker executed and return results to screen.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic