在 JavaFX 1.x 中,我使用 FX-Script 来设置场景,我有 bind 关键字:
如何在 2.0 中具有相同的行为?
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());
如果你想自动调整大小,你应该做这样的事情
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 并且它有效。此外,如果您想创建自定义组件,您的类应该扩展其中一种布局。如果您的组件扩展了窗格或组,则自动调整大小将不起作用
我想这会对你有所帮助。
最好的问候桑德罗
如果您的流程窗格有边距,您可能需要这样的东西:
innerHorizontalFlowPane.prefWidthProperty().bind(
Bindings.add(-50, stage.widthProperty()))