JavaFX 2.0:当父元素执行时,Flowpane应自动调整大小

Ron*_*Ron 2 layout resize autosize javafx-2

在JavaFX 1.x中,我使用FX-Script设置场景,我有了bind关键字:

JavaFX中的动态/即时调整大小

我怎么能在2.0中有相同的行为?

Ron*_*Ron 6

我刚刚在另一个平台上找到答案:

这很简单

FlowPane layout=new FlowPane();
layout.prefWidthProperty().bind(stage.widthProperty());
layout.prefHeightProperty().bind(stage.heightProperty());
Run Code Online (Sandbox Code Playgroud)


小智 6

如果你想自动调整大小,你应该做这样的事情

private BorderPane root;

@Override
public void start(Stage stage) throws Exception
{
   root = new BorderPane();
    //ROOT SHOULD BE ONE OF THE LAYOUTS : BorderPane, HBox, VBox, StackPane,     
    //GridPane, FlowPane
    scene = new Scene(root, 500, 500);

    stage.setScene(scene);

    stage.show();
    root.setCenter(new Label("sample label"));
}
Run Code Online (Sandbox Code Playgroud)

我只尝试过BorderPane并且它有效.此外,如果要创建自定义组件,您的类应扩展其中一个布局.如果组件扩展窗格或组,则自动调整大小将不起作用

我想这会对你有所帮助.

最好的问候桑德罗