How do I add a pane inside another pane through code like javafx?

0

I already know how to do this when it comes to AnchorPane , it's something like this:

AnchorPane ap = new AnchoPane();
Label lbl = new Label("Qualquer");
ap.getChildren().add(lbl);

But when it comes to a Pane normal, I can only call getChildrenUnmodifiable() , and if I then call add(lbl) the following exception is thrown:

  

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

Can anyone help me?

    
asked by anonymous 15.11.2017 / 19:11

1 answer

0

The Pane also has the getChildren() method. You can use it the same way as AnchorPane. Make sure you're using the correct import: import javafx.scene.layout.Pane;

See the class documentation for this link: link

To facilitate I took a print of the part that interests.

Testcodesnippet:

importjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.Label;importjavafx.scene.layout.Pane;importjavafx.stage.Stage;publicclassMainextendsApplication{@Overridepublicvoidstart(StageprimaryStage){try{Panepane=newPane();PaneotherPane=newPane();pane.getChildren().add(otherPane);Labellabel=newLabel("Qualquer");
            otherPane.getChildren().add(label);


            Scene scene = new Scene(pane,400,400);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}
    
17.11.2017 / 01:46