JavaFX VBox位置設置

          

 

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Line;
import javafx.stage.Stage;

/**
 * @Author: ZhangHao
 * @Description: 位置測試
 * @Date: 2020/5/29 9:42
 * @Version: 1.0
 */
public class PositionTest extends Application {

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

    @Override
    public void start(Stage primaryStage) {
        Pane pane = new Pane();
        pane.setPrefWidth(200);
        pane.setPrefHeight(200);
        Group group = new Group();
        group.setAutoSizeChildren(false);
        VBox vBox = new VBox();
        Button button = new Button("測試");
        button.setPrefWidth(100);
        Group group1 = new Group();
        group1.getChildren().add(button);
        vBox.getChildren().add(group1);
        vBox.setLayoutX(100);
        vBox.setLayoutY(100);
        vBox.setMinWidth(100);
        vBox.setPrefWidth(100);
//        vBox.setAlignment(Pos.CENTER);
//        vBox.setAlignment(Pos.CENTER_LEFT);
//        vBox.setAlignment(Pos.BOTTOM_RIGHT);
        vBox.setAlignment(Pos.BOTTOM_LEFT);
        group.getChildren().add(vBox);
        Line line1 = new Line(100, 0, 100, 200);
        Line line2 = new Line(0, 100, 200, 100);
        pane.getChildren().addAll(line1, line2, group);
        primaryStage.setScene(new Scene(pane));
        primaryStage.show();
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章