Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Alert box is not showing in the center of the application using JavaFX
Alert box is not showing in the center of the application using JavaFX [message #1792309] Mon, 16 July 2018 02:26 Go to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
I am trying to pop-up the box in the center of the application when I resize the application or move it.
public Boolean call(String question) {
      final Stage dialogStage = new Stage(StageStyle.UNDECORATED);
      dialogStage.initModality(Modality.WINDOW_MODAL);
      dialogStage.initOwner(owner);
      dialogStage.setTitle("ConfirmTitle"); // WIP, waiting for the strings&trans
      final Button ok = new Button(
          nmsGuiContainer.getI18nService().getMessage("com.mlnms.gui.fmwk.main.container.ok")); // WIP,
                                                                                                // waiting
                                                                                                // for
                                                                                                // the
      // strings&trans
      ok.getStyleClass().add(HTML_POPUP_BUTTON_STYLE);
      final Button cancel = new Button(
          nmsGuiContainer.getI18nService().getMessage("com.mlnms.gui.fmwk.main.container.cancel")); // WIP,
                                                                                                    // waiting
      // for the
      // strings&trans
      cancel.getStyleClass().add(HTML_POPUP_BUTTON_STYLE);
      final Text text = new Text(question);
      text.getStyleClass().add(HTML_POPUP_STYLE);
      final Insets ins = new Insets(10);
      final VBox box = new VBox();
      // box.setAlignment(Pos.BOTTOM_CENTER);
      box.setSpacing(10);
      box.setPadding(ins);
      final HBox buttons = new HBox(10);
      buttons.getChildren().addAll(ok, cancel);
      buttons.setAlignment(Pos.CENTER);
      buttons.setPadding(ins);
      box.getChildren().addAll(text, buttons);
      box.getStyleClass().add(HTML_POPUP_STYLE);
      StackPane pane = new StackPane();
      pane.setAlignment(box, Pos.CENTER);
      pane.getChildren().add(box);
      Scene scene = new Scene(pane);
      try {
        URL javafxCss = nmsGuiContainer.getBundleContext().getBundle()
            .getResource(NmsGuiContainer.JAVAFX_CSS_URL);
        scene.getStylesheets().add(javafxCss.toExternalForm());

      } catch (Exception e) {
        LOGGER.error("Cannot load the CSS file for JavaFX components ", e);
      }
      dialogStage.setScene(scene);
      ok.setCancelButton(false);

      final boolean[] res = new boolean[1];
      ok.setOnAction(new CloseDialogHandler(dialogStage, res));
      cancel.setCancelButton(true);
      cancel.setOnAction(new CloseDialogHandler(dialogStage, null));
      dialogStage.centerOnScreen();
      nmsGuiContainer.fadeContainer();
      dialogStage.showAndWait();
      nmsGuiContainer.unfadeContainer();
      return res[0];
    }
  }


This is my code. and the screenshot is as attached.

index.php/fa/33398/0/

Can anyone tell me why is this happening?

Thanks.

[Updated on: Mon, 16 July 2018 02:29]

Report message to a moderator

Re: Alert box is not showing in the center of the application using JavaFX [message #1792311 is a reply to message #1792309] Mon, 16 July 2018 03:49 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 29598
Registered: July 2009
Senior Member
This forum is intended for asking questions about how Eclipse-provided technologies work, not a general forum for asking questions about how a language like Java works or how a framework like JavaFX works. For that you're better off at something like StackOverflow.
Previous Topic:Photon crashes immediately after installation
Next Topic:Eclipse IDE makes my Alt Gr randomly work like a normal Alt
Goto Forum:
  


Current Time: Sat Oct 20 11:00:10 GMT 2018

Powered by FUDForum. Page generated in 0.03821 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top