JavaFX 2 modal window

2019-01-25 22:12发布

I'm trying to create a login window with JavaFX 2 and stop execution until the user has not logged. I want something like the below:

showLoginDialog();
showMainWindow();

showLoginDialog is responsible for creating a new stage and set its parent to be the main window. It sets the stage to be modal, I tried both WINDOW_MODAL and APPLICATION_MODAL, but as soon as the login window is showed, the showMainWindow() line is called as well.

Is it possible to stop code running until the close() of the login stage is called, or something similar? Are there any tutorials showing how this can be achieved?

标签: java javafx-2
2条回答
Deceive 欺骗
2楼-- · 2019-01-25 22:44

As Uluk said there is a JIRA issue. The issue has been closed and fixed in version 2.2 beta of JavaFX. Just use the following code if execution of the program needs to be stopped:

modalWindowStage.showAndWait();

where modalWindowStage is the stage used for showing the messagebox. If the execution needs to continue, just use the usual 'show()' method.

查看更多
倾城 Initia
3楼-- · 2019-01-25 23:03

Jira issue exists for this http://javafx-jira.kenai.com/browse/RT-19783.
Until that time you can call showMainWindow(); in an action of login button.

查看更多
登录 后发表回答