Jugaccino

Gaming News | Gaming Opinion | Playstation 4 | Xbox One | PS Vita | Film | Media

JavaFX – Vbox and Stackpane


The article will provide a user with information on Vbox and Stackpane. The VBox layout pane is similar to the HBox layout pane, except that the nodes are arranged in a single column. The padding property can be set to manage the distance between the nodes and the edges of the VBox pane. Spacing can be set to manage the distance between the nodes.

If a user is interested in creating a VBox pane then following example is best to follow:
VBox vbox = new VBox();
vbox.setPadding(new Insets(10, 10, 10, 10));
vbox.setSpacing(10);

Text title = new Text(“Data”);
title.setFont(Font.font(“Amble CN”, FontWeight.BOLD, 14));
vbox.getChildren().add(title);

Text options[] = new Text[] {
new Text(” Sales”),
new Text(” Marketing”),
new Text(” Distribution”),
new Text(” Costs”)};

for (int i=0; i<4; i++) {
vbox.getChildren().add(options[i]);
}

border.setLeft(vbox); // Add to BorderPane

As the window is resized, nodes within the VBox pane are resized according to the layout constraints assigned to the nodes.

StackPane
The StackPane layout pane places all of the nodes within a single stack with each new node added on top of the previous node. This layout model provides an easy way to overlay text on a shape or image or to overlap common shapes to create a complex shape.
In order to help a user to create a stack pane, following example will help:
StackPane stack = new StackPane();
Rectangle helpIcon = new Rectangle(35.0, 25.0);
helpIcon.setFill(new LinearGradient(0,0,0,1, true, CycleMethod.NO_CYCLE,
new Stop[]{
new Stop(0,Color.web(“#4977A3″)),
new Stop(0.5, Color.web(“#B0C6DA”)),
new Stop(1,Color.web(“#9CB6CF”)),}));
helpIcon.setStroke(Color.web(“#D0E6FA”));
helpIcon.setArcHeight(3.5);
helpIcon.setArcWidth(3.5);
Text helpText = new Text(“? “);
helpText.setFont(Font.font(“Amble Cn”, FontWeight.BOLD, 18));
helpText.setFill(Color.WHITE);
helpText.setStroke(Color.web(“#7080A0″));
stack.getChildren().addAll(helpIcon, helpText);
stack.setAlignment(Pos.CENTER_RIGHT); // Right-justify nodes in stack
HBox.setHgrow(stack, Priority.ALWAYS); // Give stack any extra space
hbox.getChildren().add(stack); // Add to HBox

The last lines of code in the example add the stack pane to the HBox pane and position it to always be at the right-most edge of the pane.

If a user has read this article then he/she would have learnt about JavaVBox and Stackpane.

Be Sociable, Share!

Leave a Comment