title: General mechanism to snap to pixel and avoid blurryness
body: <p>I'm creating a healthbar with 2 rectangles overlapping each other. The inner shows the current health, the outer shows the total health.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>The healthbar is blurry.</p>
  
  <p><strong>What I've got so far</strong></p>
  
  <p>I've read about e. g. <a href="https://stackoverflow.com/questions/27846659/how-to-draw-an-1-pixel-line-using-javafx-canvas">having to add 0.5</a>, but it only solves the problem partially.</p>
  
  <p>A screenshot, top image is without the 0.5, bottom image is with the 0.5 added.</p>
  
  <p><img src="https://i.stack.imgur.com/1Yj38.png" alt="enter image description here"></p>
  
  <p>Here's the code:</p>
  
  <pre><code>private class HealthBar extends Pane {
  
      Rectangle outerHealthRect;
      Rectangle innerHealthRect;
  
      public HealthBar() {
  
          double height = 10;
  
          double outerWidth = 60;
          double innerWidth = 40;
  
          // using 0.5, otherwise it would be blurry
          double x=snap( 0.0);
          double y=snap( 0.0);
  
          outerHealthRect = new Rectangle( x, y, outerWidth, height);
          outerHealthRect.setStroke(Color.BLACK);
          outerHealthRect.setFill(Color.WHITE);
  
          innerHealthRect = new Rectangle( x, y, innerWidth, height);
          innerHealthRect.setStroke(Color.TRANSPARENT);
          innerHealthRect.setFill(Color.LIMEGREEN);
  
          getChildren().addAll( outerHealthRect);
          getChildren().addAll( innerHealthRect);
  
      }
  
      public void setValue( double value) {
          innerHealthRect.setWidth( snap( outerHealthRect.getWidth() * value));
      }
  
      private double snap( double value) {
          return (int) value + 0.5;
      }
  }
  </code></pre>
  
  <p>After I applied scaling for debug purposes it became obvious that the transparent stroke isn't considered as transparent line of the same width like a stroke with color:</p>
  
  <p><img src="https://i.stack.imgur.com/8BNU9.png" alt="enter image description here"></p>
  
  <p><strong>Questions</strong></p>
  
  <ul>
  <li>Is there an option to snap to pixels, i. e. have sharp pixels in general without having to mess around with 0.5?</li>
  <li>How can I make the transparent stroke the same width as the outer stroke?</li>
  </ul>
  
  <p>I could try a different approach with a canvas, but these are general questions which affect the way you have to set up a JavaFX application.</p>
  
  <p>Thank you very much.</p>