首页javahboxJavaFX - 如何向HBox添加两个控件

JavaFX - 如何向HBox添加两个控件

我们想知道如何向HBox添加两个控件。
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {
    Application.launch(args);
  }

  @Override
  public void start(Stage stage) {
    Arc arc = new Arc(0, 0, 50, 100, 0, 90);
    arc.setFill(Color.GRAY);
    arc.setStroke(Color.BLACK);
    arc.setType(ArcType.ROUND);

    Arc arc1 = new Arc(0, 0, 50, 100, 0, 90);
    arc1.setFill(Color.GRAY);
    arc1.setStroke(Color.BLACK);
    arc1.setType(ArcType.ROUND);
    
    HBox box = new HBox(arc,arc1);
 
    box.setSpacing(10);    
    
    Scene scene = new Scene(box);
    stage.setScene(scene);
    stage.setTitle("Test");
    stage.show();
  }
}