Introduction to FXML has example how to build custom components with <fx:root>. Here is some snippet from the document:
public CustomControl() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("custom_control.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
Here, the constructor is leaking 'this' that might cause some unpleasure consequence.
Is it safe to pass 'this' to FXMLLoader in constructor? If not, any suggestion to make this code safe?