Answer
I think your proposal is OK from a technical viewpoint.
Opinion
From a stylistic view point the additional braces when none are really required is just a little strange to me because I have never seen anybody write code like that. However, it does read OK, has no real technical overhead and, when you consider some of the alternatives below, it doesn't require a radically different approach like a DSL or additional syntax and type constructs like creating additional methods or classes.
The more standard way I've seen stuff done is either via factory methods or inheritance. For example:
Alternatives
Builders
If builders were still around, the natural thing to do would be to use them - however builders are now deprecated, so they aren't a viable alternative. When the JavaFX team dropped builders, there were numerous replacement proposals (which you can find by following all of the posts on the builder dropping thread), but I don't think a true standard drop-in replacement was ever really found, just different options.
Factory Method
HBox top = new HBox(
createLabel("White", "white-check"),
createLabel("Light Gray", "lightgray-check")
);
. . .
public Label createLabel(String text, String styleClass) {
Label label = new Label(text);
label.getStyleClass().add(styleClass);
label.setMinWidth(160);
label.setMinHeight(60);
return label
}
Inheritance
HBox top = new HBox(
new CustomLabel("White", "white-check"),
new CustomLabel("Light Gray", "lightgray-check")
);
. . .
public class CustomLabel extends Label {
public CustomLabel(String text, String styleClass) {
super(text);
getStyleClass().add(styleClass);
setMinWidth(160);
setMinHeight(60);
}
}
Alternate Domain Specific Language
e.g. ScalaFX code:
var top = new HBox {
content = Seq(
new Label {
text = "White"
styleClass = Seq("white-check")
minWidth = 160
minHeight = 60
},
new Label {
text = "Light Gray"
styleClass = Seq("lightgray-check")
minWidth = 160
minHeight = 60
}
)
}