0
ステージをポップアップの所有者として設定しようとしていますが、所有者がアプリケーションのメインステージでない場合はポップアップは表示されません。所有者ウィンドウが表示されていない場合、JavaFXポップアップは表示されません。
public void popup(Window owner, String mensagem) {
Popup popup = new Popup();
popup.setAutoHide(true);
popup.setHideOnEscape(true);
Label label = new Label(mensagem);
label.setBackground(new Background(new BackgroundFill(Color.CORNSILK, null, null)));
popup.getContent().add(label);
popup.setOnShown((event) -> {
FadeTransition fade = new FadeTransition(Duration.seconds(5), label);
fade.setOnFinished((e) -> {
popup.hide();
});
fade.play();
});
popup.show(owner);
}
子ステージ:
public class JanelaModal extends Stage {
public JanelaModal(String title) {
super(StageStyle.DECORATED);
setTitle(title);
initOwner(Main.getInstance().getStage());
initModality(Modality.APPLICATION_MODAL);
setResizable(false);
}
public void setGui(Parent gui) {
if (getScene() != null) {
getScene().setRoot(gui);
} else {
setScene(new Scene(gui));
}
}
}
お返事ありがとうございます。ポップアップが表示されたら、所有者ウィンドウが表示されている必要があります。私の場合、子ウィンドウは閉じられているので、メインウィンドウはポップアップの所有者でなければなりません。なぜドキュメンテーションにそれが言及されていないのだろうか、それはあまり明らかではない。 – ceklock