title: Draw a polygon in javafx
body: <p>I'm trying to draw a polygon in javafx adding to its array of point the mouse coordinates. My problem is that I don't know how to make it stop when I click something else from the mouse left click.</p>
  
  <pre><code>Polygon polygon = new Polygon();
  rootPane.setOnMouseClicked((MouseEvent mouseEvent) -&gt; {
      do {
          polygon.getPoints().addAll(mouseEvent.getX(),mouseEvent.getY());
      } while(mouseEvent.getButton().equals(mouseEvent.isSecondaryButtonDown()));    
  });
  rootPane.getChildren().add(polygon);
  </code></pre>