Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

java - javafx.scene.control.Dialog<R> won't close on pressing "x"

If I just create an empty class extending from javafx.scene.control.Dialog<R>, it won't close when I'm pressing the "x" button in the top right corner.

How do I implement this behaviour? The API seems to tell me that I need to implement a close button. But in my case I don't want a close button, I just want to close the window with the x button or by pressing ESC. Is this possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The workaround from @eckig or @jewelsea works pretty fine. But I would use something like this:

// Somewhere in code
Dialog<?> dialog = new Dialog<>();
Window    window = dialog.getDialogPane().getScene().getWindow();
window.setOnCloseRequest(event -> window.hide());

I do not know any constrains of this use, but it worked for me. And I recommend initialize window right after dialog initialization, like above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...