You can use the new FX 2.2 snapshot function:
public class TrySnapshot extends Application { @Override public void start(Stage primaryStage) { final VBox vbox = new VBox(2); final Button btn = new Button(); vbox.getChildren().add(btn); btn.setText("Say 'Hello World'"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) {
If you must use an older FX, for some reason, just change the scene coordinates to your node coordinates using the Node#getBoundsInParent calls in the code sample that you linked.
source share