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.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Popup; import javafx.stage.Stage; /** * * @author slions */ public class PopupTest extends Application { public static void main(String[] args) { Application.launch(PopupTest.class, (String[]) null); } @Override public void start(Stage stage) { final Scene scene = new Scene(new Group()); stage.setTitle("PopupTest"); stage.setWidth(400); stage.setHeight(500); stage.setScene(scene); stage.show(); final Popup popup = new Popup(); popup.setAutoHide(true); popup.getContent().add(new TextField("Enter text")); final Button button = new Button("Click to edit"); button.setLayoutX(50); button.setLayoutY(50); button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { final Bounds buttonBounds = button.getLayoutBounds(); Point2D popupLocation = button.localToScreen(buttonBounds.getMinX(), buttonBounds.getMinY()); popup.setX(popupLocation.getX()); popup.setY(popupLocation.getY()); popup.show(scene.getWindow()); } }); ((Group) scene.getRoot()).getChildren().addAll(button); } }