E
Edsoncv
Hello
Recently I have implemented a swingworker dialog in order to display
a progressbar and some text while some math computations are
happening. It works fine except for one thing: I want a particular
behavior and do not know if it can be handled with swingworker, maybe
the experts can help me:
In my GUI I use a actionPerformed method to start a long task
(Swingworker), in this task I perform some calculations and update my
JprogressBar and a JTextArea. But I want some results to be displayed
right after the task is done(with printSolveMessages()), but if I call
this printing function in the next line it does not print the last
calculation result (in fact the initial value for the variables),
since the calculation is running in another thread. I tried the
swingworker.get() method, but it freezes all the GUI and the
progressbar is not updated. Any clues of how to do that?
The actionperformed class is like this:
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == startButton){
startButton.setEnabled(false);
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// task is the swingworker
task.addPropertyChangeListener(this);
task.execute();
/* the task is executing and I want a pause before
print the results with the function below, otherwhise I get
old results*/
printSolveMessages();
I also tried a while(!pMon.isDone()){} right before printSolveMessages
(); but it also locks the screen upate.
pMon is a object that tracks the start and the end of the task.
Recently I have implemented a swingworker dialog in order to display
a progressbar and some text while some math computations are
happening. It works fine except for one thing: I want a particular
behavior and do not know if it can be handled with swingworker, maybe
the experts can help me:
In my GUI I use a actionPerformed method to start a long task
(Swingworker), in this task I perform some calculations and update my
JprogressBar and a JTextArea. But I want some results to be displayed
right after the task is done(with printSolveMessages()), but if I call
this printing function in the next line it does not print the last
calculation result (in fact the initial value for the variables),
since the calculation is running in another thread. I tried the
swingworker.get() method, but it freezes all the GUI and the
progressbar is not updated. Any clues of how to do that?
The actionperformed class is like this:
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == startButton){
startButton.setEnabled(false);
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// task is the swingworker
task.addPropertyChangeListener(this);
task.execute();
/* the task is executing and I want a pause before
print the results with the function below, otherwhise I get
old results*/
printSolveMessages();
I also tried a while(!pMon.isDone()){} right before printSolveMessages
(); but it also locks the screen upate.
pMon is a object that tracks the start and the end of the task.