package javaapplication22; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.VBox; import javafx.stage.Popup; import javafx.stage.Stage; public class PopupPosition extends Application { public static void main(String[] args) { launch(args); } @Override public void start(final Stage stage) throws Exception { final Popup p = new Popup(); final Button hideButton = new Button("Popup"); hideButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { p.hide(); } }); p.getContent().add(hideButton); Button b1 = new Button("Show popup 1"); b1.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { p.setAlignWithContentOrigin(true); p.show(stage); } }); Button b2 = new Button("Show popup 2"); b2.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { p.setAlignWithContentOrigin(true); p.show(stage, 100, 100); p.setX(100); p.setY(100); } }); final Button b3 = new Button("Show popup 3"); b3.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { p.setAlignWithContentOrigin(true); p.show(b3, 100, 100); p.setX(100); p.setY(100); } }); Button b4 = new Button("Show popup 4"); b4.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { p.setAlignWithContentOrigin(false); p.show(stage); } }); Button b5 = new Button("Show popup 5"); b5.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { p.setAlignWithContentOrigin(false); p.show(stage, 100, 100); p.setX(100); p.setY(100); } }); final Button b6 = new Button("Show popup 6"); b6.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { p.setAlignWithContentOrigin(false); p.show(b6, 100, 100); p.setX(100); p.setY(100); } }); VBox vb = new VBox(b1, b2, b3, b4, b5, b6); Scene scene = new Scene(vb, 300, 300); stage.setScene(scene); stage.show(); } }