package demo; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.paint.CycleMethod; import javafx.scene.paint.LinearGradient; import javafx.scene.paint.Stop; import javafx.stage.Stage; public class BugStroke extends Application { private static final int DEFAULT_RADIUS = 40; public static void main(String[] args) { launch(args); } Group root = new Group(); private void init(Stage primaryStage) { primaryStage.setScene(new Scene(root)); primaryStage.setHeight(250); } @Override public void start(Stage primaryStage) throws Exception { init(primaryStage); primaryStage.show(); root.getChildren().add(drawNode()); } Pane borderPane; protected Pane baseFill(Pane pane) { pane.setPrefSize(180, 190); pane.setStyle("-fx-border-color: darkgray;"); return pane; } public Node drawNode() { borderPane = baseFill(new VBox()); final Canvas canvas = new Canvas(120, 120); GraphicsContext _gc = canvas.getGraphicsContext2D(); setEffect(_gc); _gc.strokeOval(DEFAULT_RADIUS / 2, DEFAULT_RADIUS / 2, 2 * DEFAULT_RADIUS, DEFAULT_RADIUS); // setEffect(_gc); borderPane.getChildren().addAll(canvas); return borderPane; } void setEffect(GraphicsContext gc) { gc.setStroke(new LinearGradient(0, 0, 1, 4, true, CycleMethod.NO_CYCLE, new Stop[]{new Stop(0, Color.RED), new Stop(0.3f, Color.BLUE)})); gc.setLineWidth(18f); gc.stroke(); // gc.fill(); } }