edvin / tornadofx-controlsfx

ControlsFX Builder extensions and utilities for TornadoFX
Apache License 2.0
71 stars 10 forks source link

Show notification when stage is not in focused #15

Open sith opened 5 years ago

sith commented 5 years ago

This is probably controlsfx question but ...

Is it possible to show notification when application is collapsed or unfocused?

edvin commented 5 years ago

It's actually more of a general JavaFX question I believe :)

In a TornadoFX UIComponent you can access the currentStage property, which is a javafx.stage.Stage. It has a focusedProperty you can listen to events on, and since Stage extends javafx.stage.Window, it also has callbacks for onShowing and onHiding.

sith commented 5 years ago

there is a scheduled task that should show notification after some time. But if app is hidden notification doesn't pop up. I am not sure I understand how this can be fixed with what you said

edvin commented 5 years ago

I misunderstood you. The title says "show notification when stage is not focused", so I thought you wanted to show a notification when the stage no longer has focus :)

You can call currentWindow?.requestFocus(), which should make the application blink in the task bar. When the user clicks the blinking application icon, your notification would appear.

sith commented 5 years ago

That's a solution :) but there is no way to show it without focus?

edvin commented 5 years ago

I'm not sure. You can check/ask on StackOverflow with a general JavaFX question. If you find a solution, please let me know on this issue :)