Based on :
Does the following code violate any JavaFX principles or is it safe
to use?
In java this code is not safe to use because you call Overridable method in constructor
and if you use Netbeans or any intellegent IDE,it will warn you with the message "Overridable method call in constructor"
and the descritpion of the problem here is :
Calling methods that can be overridden can be dangerous in the
contructor because in the moment when the overridden method is called
the object is not fully initialized.
Second,you can add children nodes in Region,Group,Containers but it is not good practice to add child node to control ,and if you need add a label to TextField you can use CustomTextField of ControlFx ,and this example of code maybe is helpful for your need :
Label myLabel=new Label("Hello");
/*You use a container if you need add many nodes in CustomTextField*/
//HBox box=new HBox();
//box.getChildren().add(myLabel);
CustomTextField customField=new CustomTextField();
customField.setRight(mylabel);
//customField.setLeft(mylabel);
//customField.setRight(box);
Or by extending CustomTextField :
//This code is safe and the warning is removing here
public class MyTextField extends CustomTextField {
public MyTextField() {
Label label = new Label("test");
this.setRight(label);
}
}