我很难尝试用圆弧剪辑圆圈。我正在尝试重现这个恒温器
来自此video (starting at 43:45)开发人员说他使用Region
s,Circle
和Arc
进行动画制作。所以我看不到如何用动画弧剪辑圆圈。
我的代码到目前为止......
//stroke is the circle without fill
stroke.setClip(arc);
我收到以下错误:
Caused by: java.lang.IllegalArgumentException: Node's clip set to incorrect value (node already connected, node = Circle[id=stroke, centerX=0.0, centerY=0.0, radius=200.0, fill=0x1f93ff00, stroke=0x63ff26ff, strokeWidth=30.0], clip = ObjectProperty [bean: Circle[id=stroke, centerX=0.0, centerY=0.0, radius=200.0, fill=0x1f93ff00, stroke=0x63ff26ff, strokeWidth=30.0], name: clip, value: null]).
那怎样才能解决这个问题?!我是仪表和恒温器应用程序的忠实粉丝。
提前致谢!!!
答案 0 :(得分:1)
有一种更简单的方法可以达到预期效果:只需使用Arc
而不使用fill
并使用适当的strokeWidth
。
示例:
@Override
public void start(Stage primaryStage) {
DoubleProperty value = new SimpleDoubleProperty();
DoubleProperty minValue = new SimpleDoubleProperty();
DoubleProperty maxValue = new SimpleDoubleProperty();
final double startOffset = 10;
final double maxRange = 360 - 2 * startOffset;
Arc arc = new Arc();
arc.setFill(null);
arc.setRadiusX(100);
arc.setRadiusY(100);
arc.setCenterX(110);
arc.setCenterY(110);
arc.setStrokeWidth(10);
arc.setStroke(Color.WHITE.deriveColor(0, 0, 1, 0.5));
arc.setStartAngle(270 - startOffset);
arc.lengthProperty().bind(value.subtract(minValue).divide(maxValue.subtract(minValue)).multiply(-maxRange));
Pane thermostatPane = new Pane();
thermostatPane.setMinSize(220, 220);
thermostatPane.getChildren().add(arc);
thermostatPane.setStyle("-fx-background-color: orange");
Slider minSlider = new Slider(0, 100, 0);
Slider maxSlider = new Slider(0, 100, 100);
Slider valueSlider = new Slider(0, 100, 20);
valueSlider.setPrefWidth(200);
maxSlider.setPrefWidth(200);
minSlider.setPrefWidth(200);
value.bind(valueSlider.valueProperty());
minValue.bind(minSlider.valueProperty());
maxValue.bind(maxSlider.valueProperty());
Scene scene = new Scene(new VBox(10, thermostatPane, minSlider, valueSlider, maxSlider));
primaryStage.setScene(scene);
primaryStage.show();
}