import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; import javafx.stage.Stage; public class CanvasTranslateBug extends Application { public static void main(String argv[]) { launch(argv); } @Override public void start(Stage stage) { Group root = new Group(); Canvas cv = new Canvas(400, 400); root.getChildren().add(cv); GraphicsContext gc = cv.getGraphicsContext2D(); gc.setFill(Color.WHITE); gc.fillRect(0, 0, 400, 400); gc.setFill(Color.BLUE); gc.setStroke(Color.GREEN); gc.setLineWidth(10); gc.scale(2, 2); for (int x = 0; x < 200; x += 80) { for (int y = 0; y < 200; y += 80) { draw(gc, x, y); } } Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } static double xPoints[] = { 0, 30, 0, 30 }; static double yPoints[] = { 0, 0, 30, 30 }; public void draw(GraphicsContext gc, double x, double y) { gc.save(); gc.translate(x, y); gc.fillOval(10, 0, 30, 30); gc.strokeOval(10, 0, 30, 30); gc.translate(0, 40); gc.fillPolygon(xPoints, yPoints, 4); gc.strokePolygon(xPoints, yPoints, 4); gc.translate(40, 0); gc.strokePolyline(xPoints, yPoints, 4); gc.restore(); } }