JavaFX HBox set background vis CSS

Description

JavaFX HBox set background vis CSS

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Main extends Application {
  @Override//from   w  w w.ja va 2s . co m
  public void start(Stage primaryStage) {
    // Create a border pane
    BorderPane pane = new BorderPane();

    // Place nodes in the pane
    pane.setTop(getHBox());

    Scene scene = new Scene(pane);
    primaryStage.setTitle("demo2s");
    primaryStage.setScene(scene);
    primaryStage.show();
  }

  private HBox getHBox() {
    HBox hBox = new HBox(15);
    hBox.setStyle("-fx-background-color: gray");
    hBox.getChildren().add(new Button("HTML"));
    hBox.getChildren().add(new Button("CSS"));
    return hBox;
  }

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



PreviousNext

Related