Can anyone explain the difference between VBoxBuilder
and VBox
in JavaFX?
VBoxBuilder boxBuilder = VBoxBuilder.create();
VBox vBox1 = new VBox();
Builders are added for convenience. They allow to create JavaFX nodes in one command without introducing new variable. It's more convenient in some situations.
Next two code snippets gives the same result, but latter doesn't create temp variable.
Without builder:
VBox vBox = new VBox();
vBox.setAlignment(Pos.CENTER);
vBox.getChildren().add(new Label("1"));
Scene scene = new Scene(vBox);
with builder:
Scene scene2 = new Scene(
VBoxBuilder.create().alignment(Pos.CENTER).children(new Label("1")).build());
N.B.: Although you may want to refrain from using builders as recently on open developers mail list an issue was raised which may lead to deprecating builders in the future releases: http://mail.openjdk.java.net/pipermail/openjfx-dev/2013-March/006725.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With