如何使VBox填充其父级的大小 [英] How to make VBox fill the size of its parent

查看:69
本文介绍了如何使VBox填充其父级的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是使VBox填充其父级的正确方法吗?

Is this the correct way to make VBox fill its parent:

    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();

推荐答案

仅使用

You can achieve the same functionality without using bind, using only BorderPane instead of Group

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

这篇关于如何使VBox填充其父级的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆