2012-02-16 18 views
8

Đây có phải là cách chính xác để làm cho VBox điền mẹ của nó:Làm thế nào để làm cho VBox điền kích thước của mẹ

final Group root = new Group(); 
    final Scene scene = new Scene(root, 1000, 800, Color.BLACK); 

    final VBox c = new VBox(); 
    c.setAlignment(Pos.TOP_CENTER); 
    c.setSpacing(10); 
    c.setFillWidth(true); 
    c.getChildren().add(...); 
    c.getChildren().add(...); 
    c.getChildren().add(...); 

    c.prefWidthProperty().bind(scene.widthProperty()); 
    c.prefHeightProperty().bind(scene.heightProperty()); 

    root.getChildren().add(c); 

    stage.setTitle("blah"); //$NON-NLS-1$ 
    stage.setScene(scene); 
    stage.show(); 

Trả lời

21

Bạn có thể đạt được các chức năng tương tự mà không sử dụng ràng buộc, chỉ sử dụng BorderPane thay vì Nhóm

final BorderPane root = new BorderPane(); 
// construct your VBox 
root.setCenter(vbox); 
1

Bạn đang mắc phải lỗi thường gặp.

Không cần tạo Nhóm làm thư mục gốc, chỉ cần trực tiếp sử dụng VBox làm thư mục gốc và thêm nó vào cảnh.

final Scene scene = new Scene(c, 1000, 800, Color.BLACK); 
Các vấn đề liên quan