javafx:用圆弧填充圆的一个百分比

3qpi33ja  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(350)


我想用灰色填充一定比例的绿色圆圈。我试图让灰色弧线占据60%的圆,但是它不起作用:

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class CircleArc  extends Application {
    @Override
    public void start(Stage applicationStage) {
        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setFitToWidth(true);

        FlowPane flowPane = new FlowPane();
        flowPane.setOrientation(Orientation.HORIZONTAL);

        Circle circle = new Circle(100);
        circle.setFill(Color.GREEN);
        Arc arc = new Arc(0, 0, 100, 100,
                -360 * 0.6, Math.toDegrees(0.6 * Math.PI));
        arc.setType(ArcType.ROUND);
        arc.setFill(Color.GRAY);

        Group group = new Group();
        group.getChildren().add(circle);
        group.getChildren().add(arc);

        flowPane.getChildren().add(group);

        scrollPane.setContent(flowPane);
        Scene scene = new Scene(scrollPane);
        applicationStage.setScene(scene);
        applicationStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

我做错什么了?

6rqinv9w

6rqinv9w1#

我想出来了。正确方法:

double rate = 0.6;
Arc arc = new Arc(0, 0, 100, 100,
                0, -360*rate);
arc.setType(ArcType.ROUND);
arc.setFill(Color.GRAY);

因此,灰色是圆圈的60%,绿色是40%。

相关问题