Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between VBoxBuilder and VBox in javafx

Can anyone explain the difference between VBoxBuilder and VBox in JavaFX?

VBoxBuilder boxBuilder = VBoxBuilder.create();
VBox vBox1 = new VBox();
like image 282
java baba Avatar asked Jan 14 '23 12:01

java baba


1 Answers

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

like image 89
Sergey Grinev Avatar answered Jan 31 '23 20:01

Sergey Grinev