I have a main stage that must open another stage without losing focus of the first one. I know i can call mainWindow.requestFocus()
after calling secondWindow.show()
but i want to make it to work without the first window even losing focus.
I wanto to do this because the second stage is a notification window with StageStyle.TRANSPARENT, that stays always on top and closes itself after some seconds. Is there a way to make the second window "unfocusable"?
JavaFX Stage is a standalone application displaying window. Stage is primary element in JavaFX. We can add as many stage as we want but we have only one primary stage.
The JavaFX Stage class is the top level JavaFX container. The primary Stage is constructed by the platform. Additional Stage objects may be constructed by the application. Stage objects must be constructed and modified on the JavaFX Application Thread.
A stage has two parameters determining its position namely Width and Height. It is divided as Content Area and Decorations (Title Bar and Borders).
Do you really need to create a new Stage
for showing your notification window? You could also use javafx.stage.Popup
which creates transparent windows by default (so you would not need to set StageStyle.TRANSPARENT
). Another advantage of using Popup
instead of Stage
is that it doesn't "steal" the focus from your main stage, wich should be pretty much what you need.
Here is some more information about the popup class: https://docs.oracle.com/javase/8/javafx/api/javafx/stage/Popup.html
And here is a simple example of how to use a popup in your application: https://gist.github.com/jewelsea/1926196
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With