/* * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. */ package tests; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Bounds; import javafx.geometry.Point2D; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.stage.Popup; import javafx.stage.Stage; /** * * @author slions */ public class Test extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { final Button button = new Button("Click on me"); button.setLayoutX(50); button.setLayoutY(50); button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { startEditingSession(button); } }); final Scene scene = new Scene(new Group(), 800, 500); final Group root = (Group) scene.getRoot(); root.getChildren().clear(); root.getChildren().addAll(button); primaryStage.setScene(scene); primaryStage.show(); } public void startEditingSession(final Node anchor) { final TextArea textArea = new TextArea(); final Popup popup = new Popup(); popup.getContent().add(textArea); final Bounds anchorBounds = anchor.getLayoutBounds(); final Point2D popupLocation = anchor.localToScreen(anchorBounds.getMinX(), anchorBounds.getMinY()); popup.setX(popupLocation.getX()); popup.setY(popupLocation.getY()); popup.show(anchor.getScene().getWindow()); } }