Source of ShowHBoxVBox.java


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