Draw a semi ring - JavaFX

后端 未结 4 1784
梦毁少年i
梦毁少年i 2020-12-11 03:47

I would like to know how to draw a semi circle in JavaFX. I tried to use Shape and QuadCurve but I couldn\'t make a perfect semicircle.

Here is a picture of what I\'

4条回答
  •  情话喂你
    2020-12-11 04:29

    Suggestions:

    • If you don't need a full outlining path, you can just use an Arc.
    • If you don't need the arc filled and just want to trace the outline path of the arc, then set the fill of the arc to null.
    • If you want the outline path of the arc thick, then set the stroke parameters on the arc.
    • If you need the a thick arc which is also outlined, then it is best to define a full arc as in Uluk's answer.

    Sample code:

    import javafx.application.Application;
    import javafx.scene.*;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.*;
    import javafx.stage.Stage;
    
    public class SemiCircleSample extends Application {
      @Override public void start(Stage stage) {
        Arc arc = new Arc(50, 50, 25, 25, 0, 180);
        arc.setType(ArcType.OPEN);
        arc.setStrokeWidth(10);
        arc.setStroke(Color.CORAL);
        arc.setStrokeType(StrokeType.INSIDE);
        arc.setFill(null);
    
        stage.setScene(new Scene(new Group(arc), 100, 80));
        stage.show();
      }
    
      public static void main(String[] args) { launch(args); }
    }
    

提交回复
热议问题