Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JavaFX 1.8U45 Dialog - how to prevent dialog from closing on pressing ESC key ? How to get Stage or

HärryJun 25 2015

Hy there,

i am implementing JavaFX 1.8U45 Dialogs.

Now i got stuck on a problem cause i cannot reach the stage or scene of the dialog.

I am trying to add an EventHandler to the dialog, to prevent it from closing by pressing ESC Key

In my Dialog extended class i try to do something like this:

getOwner().getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {

            @Override

            public void handle(KeyEvent event) {

                if (event.getCode().equals(KeyCode.ESCAPE)) {

                    LOG.info("ESC was pressed on ABFDIALOG !!");

                    event.consume();

                }

            }

        });

But get Owner is initialized by me with the baseApplications scene.

If i set the owner of the dialog to null i even cannot access its new created stage/scene

I dont know where to add my EventHandler in the dialog class and could not find the

jdk implementation where it says to close the dialog when esc is pressed ....

Thanks for hints

so long

Harry

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 23 2015
Added on Jun 25 2015
0 comments
853 views