Issue
I am migrating an application which using JavaFX
from Java 1.7
to Java 11
.
One of the error that I have is about the method StageHelper.getStages()
which has disappeared.
I did not find anything to replace it. Do you have a solution to replace this method ?
Thank you for your help ! :)
Solution
StageHelper
has been always private API, as it was part of com.sun.javafx.stage
. As such, you should be aware that private API can be changed or removed at anytime without notification.
For Java 1.7 I can't say, JavaFX (2.2?) wasn't open sourced at that time.
For Java 1.8, the StageHelper.getStages()
method can be found here.
For Java 1.9 however, StageHelper
, defined here, doesn't include getStages
anymore.
The reason for that can be found in this issue JDK-8156170: Clean up Stage and StageHelper.
If you read the description, as part of the issue they will:
Remove
getStages()
and make caller of this method to use public APIWindow.getWindows()
.
Alternatives
As mentioned in that issue, since JavaFX 9 you have this public method Window.getWindows()
, that will
return a list containing a reference to the currently showing JavaFX windows
Note that a Window
can be a Stage
or a PopupWindow
, so maybe you can filter them out:
List<Stage> stages = Window.getWindows().stream()
.filter(Stage.class::isInstance)
.map(Stage.class::cast)
.collect(Collectors.toList());
Answered By - José Pereda
Answer Checked By - David Marino (JavaFixing Volunteer)