2

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

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

如何在 2.0 中具有相同的行为?

4

3 回答 3

6

I've just found the answer on another plattform:

It is as easy as

FlowPane layout=new FlowPane();
layout.prefWidthProperty().bind(stage.widthProperty());
layout.prefHeightProperty().bind(stage.heightProperty());
于 2011-11-01T12:31:44.703 回答
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"));
}

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

我想这会对你有所帮助。

最好的问候桑德罗

于 2011-11-20T14:26:15.630 回答
0

如果您的流程窗格有边距,您可能需要这样的东西:

  innerHorizontalFlowPane.prefWidthProperty().bind(
      Bindings.add(-50, stage.widthProperty()))
于 2016-08-17T13:42:20.803 回答