title: JavaFX: How to use GraphicsContext.fillText?
body: <p>So I'm trying to make a custom Node in my JavaFX application, which extends from the <code>Canvas</code> and thus does all its own rendering. I started by simply trying to draw the text &quot;Hello world.&quot; on the canvas, but alas it does not appear, even while I can confirm the existence of the custom node in my application via the mouse event handlers.</p>
  <pre class="lang-java prettyprint-override"><code>public class EditorFragment extends Canvas {
      public EditorFragment() {
          super(100, 30);
          this.render(this.getGraphicsContext2D());
          this.addEventFilter(MouseEvent.MOUSE_CLICKED, mouseEvent -&gt; {
              System.out.println(&quot;Mouse event occurred in fragment.&quot;);
              System.out.println(mouseEvent.toString());
          });
          this.setOnMouseMoved(mouseEvent -&gt; {
              System.out.println(&quot;Mouse moved over fragment.&quot;);
          });
      }
  
      protected void render(GraphicsContext gc) {
          gc.setFill(Color.BLACK);
          gc.fillText(&quot;Hello world.&quot;, 0, 0);
      }
  }
  </code></pre>
  <p>So in short, if I add a new instance of this <code>EditorFragment</code> to, let's say, a <code>Pane</code>, I know that it is added, and if I would call <code>gc.fillRect(...)</code>, I'd see a rectangle showing the node's position and size, but text is not being shown. Why?</p>