1

How do I show a popup window using either PopupWindow or Popup from JavaFX 2.0? I can't find any tutorials or samples.

1 Answer 1

4
public class test extends Application{ Stage primaryStage; @Override public void start(final Stage stage) throws Exception { primaryStage = stage; Button showPopUp = new Button("Pop Up"); final TextField name = new TextField(); VBox vBox = new VBox(); vBox.getChildren().add(name); vBox.getChildren().add(showPopUp); final Label hello = new Label(); final TextField name2 = new TextField(); Button ok = new Button("ok"); Button cencel = new Button("cancel"); VBox popUpVBox = new VBox(); popUpVBox.getChildren().add(hello); popUpVBox.getChildren().add(name2); popUpVBox.getChildren().add(ok); popUpVBox.getChildren().add(cencel); final Popup popup = new Popup(); popup.setAutoFix(false); popup.setHideOnEscape(true); popup.getContent().addAll(popUpVBox); popup.setX(250); popup.setY(175); ok.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { name.setText(name2.getText()); } }); cencel.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { popup.hide(); } }); showPopUp.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { if (popup.isShowing()) { popup.hide(); } else { hello.setText("hello.."+name.getText()); popup.show(stage); } } }); Scene scene = new Scene(vBox); primaryStage.setScene(scene); primaryStage.setWidth(200); primaryStage.setHeight(200); primaryStage.show(); } } 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man, the popup class works perfectly on full screen mode. At first I created another window using Modality.Application_Window, but it did not suit the full screen mode.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.