0

I am building an app and I want to put in every page in the app the text "hello" with the label that writes the name of the client that is connected now ,how can I do that ??? for example : if I am connected now, in the top of all the pages in the app I will see hello Nadeen

1 Answers1

2

Use composition, not inheritance.

Inheritance is the wrong concept to try to achieve something like this. Instead add create a parent layout for this and add functionality to display content in it.

Example:

public class ParentController {

    @FXML
    private StackPane container;

    public void setContent(Node content) {
        // replace old container content
        container.getChildren().setAll(content);
    }

    // code for setting the name...

}
<VBox>
    <children>
        <Label text="Nadeen"/>
        <StackPane fx:id="container" VBox.vgrow="ALWAYS"/>
    <children>
</VBox>

This allows you to replace the content with the results of loading different fxml files.

ParentController controller = ...;
controller.setContent(someNode);
...
controller.setContent(someOtherNode);

Make sure you properly access the controller as described here:

Passing Parameters JavaFX FXML

You could also go with the custom component approach...

fabian
  • 80,457
  • 12
  • 86
  • 114