Posted by
xemfo on
Oct 14, 2024; 8:35am
URL: https://forum.jogamp.org/Placing-a-NewtCanvasJFX-within-other-JavaFX-layout-elements-tp4043329p4043584.html
Hi! New user here. Did you get any further with this? I'm having the exact same issue, except in my case the NewtCanvasJFX is in a StackPane, which itself is the center node of a BorderPane.
Here's my code:
----
fx_ = new FXControl(); // FXControl inherits NewtCanvasJFX
StackPane fxPane = new StackPane();
fxPane.getChildren().add(fx_);
Label topLabel = new Label("Top label");
fxPane.getChildren().add(topLabel);
Label label = new Label("Label 1");
label.setPrefWidth(100);
Label label2 = new Label("Label 2");
label2.setPrefWidth(100);
BorderPane root = new BorderPane();
root.setLeft(label);
root.setCenter(fxPane);
root.setRight(label2);
Scene scene = new Scene(root, 800, 600);
fx_.widthProperty().bind(fxPane.widthProperty());
fx_.heightProperty().bind(fxPane.heightProperty());
----
Running this, here's the result:

Just like in leeca's case, the NewtCanvasJFX is rendered with the correct size, but at the wrong position (ignoring the 100 px offset created by the label in the left part of the BorderPane).
By accident I noticed that if I bind the width and height properties to root's counterparts instead of to fxPane's, i.e. if the last two lines are changed to this:
----
fx_.widthProperty().bind(root.widthProperty());
fx_.heightProperty().bind(root.heightProperty());
----
then the result instead looks like this:

Now, the change in binding of the width and height properties seems to have changed something in the positioning as well as the top left is now positioned correctly (the leftmost label is no longer covered). Instead the rightmost label is covered, but that's expected since the NewtCanvasJFX node is now (correctly) the same size as the BorderPane.
I have an additional problem as well, namely that the z-order of the StackPane also seems to be ignored. Unless I'm mistaken, the topLabel in my code example should have been rendered on top of the fxPane.
I forgot to mention, I'm on JDK 23, JavaFX 23, Jogamp 2.5.0