import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * The simplest VBox: three labels in a column.
 * Resize the window and watch what stays put and what moves.
 *
 *   setPadding    space INSIDE the VBox, between its edge and its children
 *   setSpacing    space BETWEEN neighboring children
 *   setMargin     space OUTSIDE one child (set through VBox, not the child)
 *   setAlignment  where the column of children sits inside the VBox
 *   setVgrow      which child takes the spare height
 *
 * Edit a value, run again, resize the window.
 */

public class SimpleVBoxDemo extends Application {

	// A colored label with a fixed preferred size so you can see its edges.
	private Label label ( String text, String color ) {
		Label label = new Label(text);
		label.setPrefSize(140,40);
		label.setAlignment(Pos.CENTER); // the text inside the label
		label.setStyle("-fx-background-color: " + color
		    + "; -fx-border-color: #333;");
		return label;
	}

	@Override
	public void start ( Stage stage ) {
		Label one = label("1","#cfe8ff");
		Label two = label("2","#c8f0c8");
		Label three = label("3","#ffe0b3");

		VBox column = new VBox(one,two,three);
		column.setStyle("-fx-background-color: #eeeeee;");

		// ---- setPadding: space inside the VBox's edge ----
		column.setPadding(new Insets(15)); // top, right, bottom, left all 15
		// try: column.setPadding(new Insets(10, 10, 10, 60)); // top, right,
		// bottom, left

		// ---- setSpacing: space between children ----
		column.setSpacing(10);
		// try: column.setSpacing(30);

		// ---- setMargin: space around ONE child (note: it is a VBox method) ----
		VBox.setMargin(two,new Insets(20,0,0,0)); // top, right, bottom, left
		// try: VBox.setMargin(two, new Insets(0, 0, 0, 40));

		// ---- setAlignment: where the children sit inside the VBox ----
		column.setAlignment(Pos.TOP_CENTER); // the default is TOP_LEFT
		// try: column.setAlignment(Pos.BOTTOM_RIGHT);
		// try: column.setAlignment(Pos.CENTER);

		// ---- fillWidth: do the children stretch to the full width? ----
		// The labels have a fixed size here, so nothing changes until you also let
		// one stretch:
		// try: two.setMaxWidth(Double.MAX_VALUE); // 2 now fills the width
		// (fillWidth is true by default)
		// try: column.setFillWidth(false); // children never stretch sideways

		// ---- grow: give the spare height to one child ----
		// try (uncomment both lines; label 3 stretches downward):
		// three.setMaxHeight(Double.MAX_VALUE); // allowed to stretch
		// VBox.setVgrow(three, Priority.ALWAYS); // gets the spare height

		stage.setScene(new Scene(column,300,300));
		stage.setTitle("VBox");
		stage.show();
	}

	public static void main ( String[] args ) {
		launch(args);
	}
}
