Search code examples
javajavafx-2javafxrectangles

JavaFX2.x Rectangle rounded corners are not shown


Just a little problem, but I don't know how to fix it and Papa google couldn't help either. I am drawing a rectangle with javafx2 and I want to have rounded corners. However the rectangle is shown with all the properties, except the rounded corners. Here is my code:

   rectPasse = new Rectangle();
   rectPasse.setTranslateX(-160);
   rectPasse.setTranslateY(-160);
   rectPasse.setWidth(54);
   rectPasse.setHeight(140);
   rectPasse.setArcWidth(5);
   rectPasse.setArcWidth(5);
   rectPasse.setFill(Color.RED);  

later on I add the rectangle to the stage:

   screensController.getChildren().add(rectPasse);

Like I said, it is shown perfectely, just no rounded corners.
If you know why, please let me know.


Solution

  • This is just a simple typo, you set the arc width twice:

    rectPasse.setArcWidth(5);
    rectPasse.setArcWidth(5);
    

    Instead, you should set both the arc width and height:

    rectPasse.setArcWidth(5);
    rectPasse.setArcHeight(5);