In my JavaFX application, I want to embed elements to my scene graph that are drawn directly by native libraries. While this seems very similar to Swing integration, it is somewhat different, because my Java application code does not draw items in the window - that is done exclusively by a native library.
I am currently able create something very close, by creating a new Stage with StageStyle.UNDECORATED. I set the owner of this stage to be the window of my current scene. I create listeners on the owner window's X and Y properties to move my undecorated stage when the parent window moves.These listeners keep the child window properly positioned. The owner relationship keeps my child window on top and support minimizing and maximizing of the owner window properly. I have a Control object that acts as a proxy for my child window in the scene graph to make sizing of the window work.
There are four things that is sub optimal with my work-around:
1) I need to use reflection against the JavaFX Window object and reach down into implementation classes to get the HWND of my child window
2) When there is mouse activity in my child window, the parent window loses focus and its decoration reflects the case, confusing users
3) I cannot take advantage of the JavaFX event filters in Parent Nodes of my child window. It would be great if my control object could get mouse events from the window
4) I need a to carefully control the some lifecycle events because I cannot pass the HWND to the native library too early - I need a listener on the owner window for WINDOW_SHOW to validate that the window is ready for the native library to use.
As a side note, I did try working with PopupWindows but without success. I believe this is because they are transparent, as my otherwise functional code would not work with a StageStyle.TRANSPARENT either.
I can understand if the realities of the windowing systems make any improvements impossible or if my request is so rare that it doesn't warrant effort. Thank you for your consideration and comments.
I am currently able create something very close, by creating a new Stage with StageStyle.UNDECORATED. I set the owner of this stage to be the window of my current scene. I create listeners on the owner window's X and Y properties to move my undecorated stage when the parent window moves.These listeners keep the child window properly positioned. The owner relationship keeps my child window on top and support minimizing and maximizing of the owner window properly. I have a Control object that acts as a proxy for my child window in the scene graph to make sizing of the window work.
There are four things that is sub optimal with my work-around:
1) I need to use reflection against the JavaFX Window object and reach down into implementation classes to get the HWND of my child window
2) When there is mouse activity in my child window, the parent window loses focus and its decoration reflects the case, confusing users
3) I cannot take advantage of the JavaFX event filters in Parent Nodes of my child window. It would be great if my control object could get mouse events from the window
4) I need a to carefully control the some lifecycle events because I cannot pass the HWND to the native library too early - I need a listener on the owner window for WINDOW_SHOW to validate that the window is ready for the native library to use.
As a side note, I did try working with PopupWindows but without success. I believe this is because they are transparent, as my otherwise functional code would not work with a StageStyle.TRANSPARENT either.
I can understand if the realities of the windowing systems make any improvements impossible or if my request is so rare that it doesn't warrant effort. Thank you for your consideration and comments.
- relates to
-
JDK-8375663 Support for embedding native OS-level rendering surfaces into JavaFX Scene
-
- Open
-