title: Filling a Health Bar over time Javafx
body: <p>this is my first post. I looked through similar questions but couldn't find anything that helped.
  So I'm trying to programm a little RPG for practicing javafx and I managed to implement a fighting system that works. Now I want to write a resting method, that regenerates health over time.
  It wrote is so that every second it regenerates 10% of the max health which works, but it doesn't show the progress. The bar only fills once the method is finished, but I would like to see every tick.</p>
  <pre><code>package application;
  
  import javafx.geometry.Insets;
  import javafx.geometry.Pos;
  import javafx.scene.control.Button;
  import javafx.scene.control.Label;
  import javafx.scene.layout.BorderPane;
  import javafx.scene.layout.GridPane;
  import javafx.scene.paint.Color;
  import javafx.scene.shape.Rectangle;
  
  public class RootBorderPane extends BorderPane
  {
      Rectangle healthCurrent;
      Label healthBorder;
      GridPane grid;
      Button heal;
      Button reset;
      private double health;
  
      
      public RootBorderPane()
      {
          innitComponents();
          addComponents();
          addHandlers();
      }
      
      
      
      private void addHandlers()
      {
          heal.setOnAction( event -&gt; heal());
          reset.setOnAction( event -&gt; reset());
      }
      
      
      private void innitComponents()
      {
          grid = new GridPane();
          
          healthCurrent = new Rectangle(100, 20, Color.RED);
          healthBorder = new Label(&quot;&quot;,  healthCurrent);
              healthBorder.setMinHeight(20);
              healthBorder.setMinWidth(100);
              healthBorder.setAlignment(Pos.CENTER_LEFT);
              healthBorder.setStyle(&quot;-fx-border-color: red;&quot;);
              healthBorder.setPadding(new Insets(2, 2, 2, 2));
              setHealth(1);
              healthCurrent.setWidth(getHealth());
          heal = new Button(&quot;heal&quot;);
          reset = new Button(&quot;reset&quot;);
              
      }
      
      private void addComponents()
      {
          grid.add(healthBorder, 0, 0, 2, 1);
          grid.add(heal, 0, 1, 1, 1);
          grid.add(reset, 1, 1, 1, 1);
          
          setCenter(grid);
      }
      
      private void heal()
      {
          if(health &lt;= 100)
          {
              fillBar();
          }
      }
      
      private void fillBar()
      {
          if(getHealth() &lt; 100)
          {
              setHealth(getHealth() +10);
              healthCurrent.setWidth(getHealth());
              try
              {
                  Thread.sleep(1000);
              } catch (InterruptedException e)
              {
                  e.printStackTrace();
              }
          }
          else
          {
              setHealth(100);
              healthCurrent.setWidth(getHealth());
              try
              {
                  Thread.sleep(1000);
              } catch (InterruptedException e)
              {
                  e.printStackTrace();
              }
          }
      }
      
      private void reset()
      {
          setHealth(1);
          healthCurrent.setWidth(getHealth());
          
      }
      
      public void setHealth(double health)
      {
          this.health = health;
      }
      
      public double getHealth()
      {
          return health;
      }
  }
  </code></pre>
  <p>I wrote the heal() and fillBar() as two methods because i hoped that would make a difference, but it didn't.</p>
  <p>Thank you in advance and I hope I'm not violating to many coding conventions.</p>