1  import javafx.application.Application;
  2  import javafx.geometry.Insets;
  3  import javafx.scene.Scene;
  4  import javafx.scene.control.Button;
  5  import javafx.scene.control.Label;
  6  import javafx.scene.layout.BorderPane;
  7  import javafx.scene.layout.HBox;
  8  import javafx.scene.layout.VBox;
  9  import javafx.stage.Stage;
 10  import javafx.scene.image.Image;
 11  import javafx.scene.image.ImageView;
 12  
 13  public class ShowHBoxVBox extends Application {
 14    @Override // Override the start method in the Application class
 15    public void start(Stage primaryStage) {
 16      // Create a border pane 
 17      BorderPane pane = new BorderPane();
 18  
 19      // Place nodes in the pane
 20      pane.setTop(getHBox()); 
 21      pane.setLeft(getVBox());
 22      
 23      // Create a scene and place it in the stage
 24      Scene scene = new Scene(pane);
 25      primaryStage.setTitle("ShowHBoxVBox"); // Set the stage title
 26      primaryStage.setScene(scene); // Place the scene in the stage
 27      primaryStage.show(); // Display the stage
 28    }
 29    
 30    private HBox getHBox() {
 31      HBox hBox = new HBox(15); // Create an HBox with 15px spacing
 32      hBox.setPadding(new Insets(15, 15, 15, 15));
 33      hBox.setStyle("-fx-background-color: gold");
 34      hBox.getChildren().add(new Button("Computer Science"));
 35      hBox.getChildren().add(new Button("Chemistry"));
 36      ImageView imageView = new ImageView(new Image("image/us.gif"));
 37      hBox.getChildren().add(imageView);
 38      return hBox;
 39    }
 40    
 41    private VBox getVBox() {
 42      VBox vBox = new VBox(15); // Create a VBox with 15px spacing
 43      vBox.setPadding(new Insets(15, 5, 5, 5));
 44      vBox.getChildren().add(new Label("Courses"));
 45      
 46      Label[] courses = {new Label("CSCI 1301"), new Label("CSCI 1302"), 
 47          new Label("CSCI 2410"), new Label("CSCI 3720")};
 48  
 49      for (Label course: courses) {
 50        VBox.setMargin(course, new Insets(0, 0, 0, 15));
 51        vBox.getChildren().add(course);
 52      }
 53      
 54      return vBox;
 55    }
 56    
 57    /**
 58     * The main method is only needed for the IDE with limited
 59     * JavaFX support. Not needed for running from the command line.
 60     */
 61    public static void main(String[] args) {
 62      launch(args);
 63    }
 64  }