• Post Reply Bookmark Topic Watch Topic
  • New Topic

Controls not updating until method is completely finished  RSS feed

 
Michael D Sims
Ranch Hand
Posts: 113
1
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have this method that does several RegEx queries along with a lot of searching and replacing of text, and each regex search / replace takes some time and a total of maybe two minutes for all of them to finish up. So I added a ProgressBar to my JavaFX form and I added code after each step to simply use the ProgressBar.setProgress method by a factor of 10% each step ... so the code would resemble something like this:



Hopefully you get the gist of it.

What is happening is that the progress bar will not actually paint any progress until AFTER the entire method is done executing. So from the users perspective, they click on the button and the program appears to freeze until its all done with that method at which point it instantly changes the progress bar to the last value I set ...

So the desired effect is simply not working, and I don't know why.

I tried changing (as in replacing the progress bar with a different control) the progress bar value settings with updating text in a text box on the form, and even that didn't display any of the text messages until AFTER the procedure was done executing at which point, all of the text logs appeared at one time instead of gradually adding text to the box in increments as the method executed.So it FEELS like any time a method is actually running, the JavaFX scene simply freezes until the method is done running. And it doesn't matter if I change the progress bars value directly or put it into its own method which gets called throughout the execution of the regex method ... either way, nothing actually happens on the form until the software is done executing all of the procedures called and then it comes back to a "resting" state...

I tried simplifying it by making a single method that does two things ... it updates the progress bar and then it waits for 1 second. Then it increments a variable then updates the progress bar, then waits a second, thinking to myself that 1 second pause would give it time to update the progress bars value but even that little method would not work.

Here is the test method I created:



Even that little piece of code will not actually show any changes in the progress bar until after its done looping at which point, the progress bar is filled to 100%, but I never see the first 9 changes in the progress bar within that for next loop.

Can someone help me understand why this thing behaves like this?

Thank you,

Mike Sims
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael D Sims wrote:What is happening is that the progress bar will not actually paint any progress until AFTER the entire method is done executing. So from the users perspective, they click on the button and the program appears to freeze until its all done with that method at which point it instantly changes the progress bar to the last value I set ...

This is pure guesswork on my part because I am NOT a GUI expert, but I suspect that you may need to repaint() (or whatever) the progress bar before you see it.

I would say, however, that a progress bar might not be the right thing for a regex. It's usually used for situations when you have LOTS of thing to do, and can give the user some idea of "progress". If you only have 5 or 6. I'm not sure that it's going to give your users any "yes I can see it's doing something" feelings.

But I may be wrong. When it comes to GUIs, I know nothing.

Winston
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should really read Concurrency in Swing. In this case, the call to sleep blocks your entire GUI, including repaints.
 
Michael D Sims
Ranch Hand
Posts: 113
1
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:I would say, however, that a progress bar might not be the right thing for a regex. It's usually used for situations when you have LOTS of thing to do, and can give the user some idea of "progress". If you only have 5 or 6. I'm not sure that it's going to give your users any "yes I can see it's doing something" feelings.


Hi Winston, and Thank You for taking the time to comment on my post. In this particular case, I, myself, was concerned several times during testing, that the program simply froze up and I ended up manually killing it so that I could run it via debug and step through it. It's not the RegEx queries themselves that take time, it's the subsequent search and replace tasks that I end up doing on this data. Sometimes it can take several minutes, and I quickly realized that even a clunky progress bar that is updated in dis-synchronized time (ie it goes in 10 steps and the first 4 steps happen within seconds but the 5th step takes about 2 minutes) ... at least seeing a progress bar as opposed to absolutely nothing re-assures the user that the program isn't locked up and in need of a three finger salute.

Besides, I've never done a progress bar before ... it's fun for me and makes things more challenging which is always a welcome thing.

Mike Sims
 
Michael D Sims
Ranch Hand
Posts: 113
1
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:You should really read Concurrency in Swing. In this case, the call to sleep blocks your entire GUI, including repaints.

Hi Rob, thank you for your time ... I was actually afraid that sleep would in fact sleep everything (I wonder if this is true for active threads). I opened the link you posted and just now read the first page, and you've been reading my mind, because before coming back and checking on this post, I read an Oracle tutorial on threads... your reference looks more applicable to my needs in this situation, however.

Thank you,

Mike Sims
 
Michael D Sims
Ranch Hand
Posts: 113
1
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:You should really read Concurrency in Swing. In this case, the call to sleep blocks your entire GUI, including repaints.

Rob, do you have links to any similar documents specifically aimed at the JavaFX environment? I've been reading this link for a couple of hours now, but I think I'm stuck on actually implementing it in practice because of some slight differences between JavaFX controllers and Swing controllers.

Aside from that, I think I have at least a beginners understanding of how Threading works, along with some of its various features (depending on which class you use of course) thanks to that link.

Mike
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest, I have no idea how JavaFX handles threading issues. A quick search resulted in this link; perhaps that's enough for you.
 
Michael D Sims
Ranch Hand
Posts: 113
1
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:To be honest, I have no idea how JavaFX handles threading issues. A quick search resulted in this link; perhaps that's enough for you.

It looks like we found the same article, only laid out differently

Here is the one I found: Concurrency in JavaFX

I used Example 3 and I’ll be damned if it didn’t work! I was even able to bind the progress bar from a NON-instantiating class to the thread, and it worked!

My issue now is a Regex one (Actually patterns and matchers) so I’m going to post that in the appropriate forum.

Thank you again for responding. I’m convinced our learning curve would be substantially steeper without the Internet and peer support.

Michael Sims
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed that I posted the JavaFX 8 version and you found the JavaFX 2 version (note that that's just one version difference - JavaFX went from 2.x to 8 together with Java 8).
 
Michael D Sims
Ranch Hand
Posts: 113
1
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:I noticed that I posted the JavaFX 8 version and you found the JavaFX 2 version (note that that's just one version difference - JavaFX went from 2.x to 8 together with Java 8).

Thank you for pointing that out. I’ll look over the 8 version to make sure I didn’t miss anything new that I should be knowing.

:-)

Michael
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!