/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ import javafx.application.Application; import javafx.builders.SceneBuilder; import javafx.builders.StackPaneBuilder; import javafx.builders.StageBuilder; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; /** * * @author Alexander Kouznetsov */ public class RenderToImageBug extends Application{ @Override public void start(Stage primaryStage) { Circle node = new Circle(30, Color.RED); Scene scene = SceneBuilder.create().fill(Color.BLUE).width(100).height(100) .root(StackPaneBuilder.create().children(node).build()).build(); // scene.getRoot().layout(); <-- This is workaround Object renderToImage = scene.renderToImage(null); System.out.println("renderToImage = " + renderToImage); Image sceneImage = Image.impl_fromPlatformImage(renderToImage); Stage stage2 = StageBuilder.create() .x(100) .scene(SceneBuilder.create().width(100).height(100) .root(new Group(new ImageView(sceneImage))).build()) .build(); stage2.setVisible(true); primaryStage.setScene(scene); primaryStage.setVisible(true); } public static void main(String[] args) { launch(args); } }