VBox_HBox_Css1
 
  • The VBox layout places child nodes stacked in a vertical column. The new added children are placed beneath the previous child node.
  • The HBox layout class places child nodes in a horizontal row. New child nodes are appended at the end of the right side of a preceding element.
 
Codes:
 
package javafxtemplate1;

import java.sql.SQLException;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class JavaFXTemplate1 extends Application {

@Override
    public void start(Stage primaryStage)throws SQLException {
        StackPane root = new StackPane();
        HBox hbox = new HBox(30);
        //
      VBox vbox1 = new VBox(10);
      Label label1 = new Label("Label1");
      //label1.setStyle("-fx-background-color: 
      //slateblue; -fx-text-fill: white;");
      //OR
      label1.getStyleClass().add("label1");
      TextField txtbox1 = new TextField();
      vbox1.getChildren().addAll(label1,txtbox1);
      //
       VBox vbox2 = new VBox(10);
      Label label2 = new Label("Label2");
      label2.getStyleClass().add("label2");
      TextField txtbox2 = new TextField();
      txtbox2.getStyleClass().add("txtbox2");
      vbox2.getChildren().addAll(label2,txtbox2);
      //HBox.setHgrow(vbox2, Priority.ALWAYS);
      // stack panehbox
       StackPane.setMargin(hbox, new Insets(20));
      //
       hbox.getChildren().addAll(vbox1, vbox2);
       Scene scene = new Scene (hbox, 300, 250); 
       primaryStage.setScene(scene);
      // scene.getStylesheets().add
       //("http://manas9/BareBone_JavaCore/JavaFxCSS1.css");
       //OR
       scene.getStylesheets().add(javafxtemplate1.
         JavaFXTemplate1.class.getResource
        ("JavaFxCSS1.css").toExternalForm());
       primaryStage.show(); 

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

CSS

.root{
    
    -fx-background-color: burlywood;
}
.label1{
    -fx-font-size: 14pt;
    -fx-font-family: "Segoe UI Semibold";
    -fx-background-color:white; 
    -fx-text-fill: red;
    -fx-opacity: 0.6;
}
.label2{
    -fx-font-size: 14pt;
    -fx-background-color:purple; 
    -fx-text-fill: white;
}
.txtbox2{
    -fx-background-color: greenyellow; 
    -fx-text-fill: red;
}
		
Runtime Display