我在javafx中绘制时间轴动画。这是创建行的代码:
public Line getLine() {
Point startPoint = FigureUtil.translateGeographicalToViewCoords(center.longitude, center.latitude, mapViewState);
line = new Line();
line.setStartX(startPoint.x);
line.setStartY(startPoint.y);
line.setStrokeWidth(4);
line.setStyle("-fx-stroke: rgba(37, 176, 79, 0.5);");
return line;
}
public void stop(){
timer.stop();
timeline.stop();
}
private KeyFrame getFrame() {
Duration duration = Duration.millis(60/speedOfRotating);
EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
LatLong latLong = LongitudeLatitudeUtil.getLatLongByDistanceAndAngle(center, time, size);
Point endPoint = FigureUtil.translateGeographicalToViewCoords(latLong.longitude, latLong.latitude, mapViewState);
line.setEndX(endPoint.x);
line.setEndY(endPoint.y);
time++;
}
};
KeyFrame keyFrame = new KeyFrame(duration, onFinished);
return keyFrame;
}
private void startTimer() {
timer = new AnimationTimer() {
@Override
public void handle(long l) {
time++;
if (time > 360) {
time = 0;
}
}
};
timer.start();
}
public void start() {
startTimer();
timeline = new Timeline();
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.setAutoReverse(true);
// You can add a specific action when each frame is started.
// timeline.getKeyFrames().remove(1);
timeline.getKeyFrames().add(getFrame());
timeline.play();
}
当我添加添加到窗格时,我遇到了这样的问题:[1]:http://img.image-storage.com/69224197/be380fee3e074.jpg。 从我添加到它的窗格中看不到行(它用虚线分隔)。
答案 0 :(得分:0)
您可以使用剪辑来屏蔽节点的特定区域:
Line line = LineBuilder.create().endX( 250 ).endY( 250 ).build();
// pane to clip
FlowPane pane = FlowPaneBuilder.create().minHeight( 200 ).minWidth( 200 ).children( line ).build();
// clipping shape
Rectangle rect = RectangleBuilder.create().x(pane.getLayoutX()).y(pane.getLayoutY()).width( pane.getMinWidth() ).height( pane.getMinHeight() ).build();
pane.setClip( rect );
答案 1 :(得分:0)
您可以简单地为容器节点指定要添加行的剪辑。
linesContainer.setClip(RectangleBuilder.create().width(linesContainer.getWidth()).height(linesContainer.getHeight()).build());