Chappi
Chappi

Reputation: 23

JavaFX Making dialog blink like native windows dialogs

I'm trying to create a custom dialog window in JavaFX. It's simply loading a fxml and everything is fine apart from one cosmetic thing that bugs me out. When I click outside of the dialog, it does correctly block the interaction - but the dialog doesn't blink like the native dialogs in windows. I've seen a question about C++ and QT and it had something to do with the dialog parent, but I can't find anything about JavaFX sadly.

Upvotes: 2

Views: 906

Answers (1)

n247s
n247s

Reputation: 1918

I haven't found this functionality in javafx yet. But with most of these things, you may accomplish this with the awt library.

Take a look at this post for more information about it. I hope you can use it with javafx though.I haven't tested it, but I have my doubts about it.

Edit

I did some testing and for me using Modality.WINDOW_MODALITY for the stage works as espected. (when trying to unfocus it makes a sound, and it blinks. unless the whole application is unfocused). This is a simple example of the constructor I use for secondary windows.

public SecondaryWindow(Window parent, String title, Modality modality, int width, int height)
{
    // basic setup
    this.stage = new Stage();
    this.root = this.loadRoot();

    this.stage.setScene(new Scene(root, width, heigth));
    this.stage.setMinWidth(this.root.minHeight(-1));
    this.stage.setMinHeight(this.root.minHeight(-1));

    this.stage.initModality(modality);
    this.stage.setTitle(title);
    this.stage.initOwner(window);


    // this will blink your application in the taskbar when unfocused.
    this.stage.focusProperty().addListener(E -> this.stage.toFront());

    // this is quickfix to prevent Alt+ F4 on a secondary screen.
    this.stage.addEventFilter(KeyEvent.KEY_RELEASED, E -> {
            if(E.getCode() == KeyCode.F4 && E.isAltDown())
            {
                E.consume();
                this.ignoreCloseRequest = true;
            }
        });

        this.stage.setOnCloseRequest(E -> {
            if(!this.ignoreCloseRequest)
                this.close();
            E.consume();
            this.ignoreCloseRequest = false;
        });
}

I hope this helps a bit more in your situation.

Upvotes: 1

Related Questions