0

我正在尝试设置我的 javafx 场景,但我失败得很惨。基本上我想做的是根据所附照片。

在此处输入图像描述

我试图设置一个网格窗格,然后将另一个网格窗格放置在其中,以便我可以设置框和标签,但这不能正常工作。

我不想使用 FXML。

你们能推荐如何进行这个设置吗?

4

2 回答 2

0

JavaFx SceneBuilder 是一个很好的工具,可以创建您想要的布局。看看官方网站。该工具会创建一个 FXML 文件,您可以使用以下方法将其加载到您的应用程序start()方法中:

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("application.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
}

您可以熟悉 SceneBuilder 的另一个资源是Youtube上的 #Java 和 #OracleLearning 频道。

于 2013-08-24T09:26:11.713 回答
0

此代码在设置给定安排时对我有用:

GridPane outerPane = new GridPane();
GridPane innerPane1 = new GridPane();
GridPane innerPane2 = new GridPane();
HBox l = new HBox(new Label("Label"));
l.setAlignment(Pos.CENTER);
outerPane.add(l, 1, 1);
innerPane1.add(new Circle(20, Color.LIGHTCORAL), 1, 1);
outerPane.add(innerPane1, 2, 1);
innerPane2.add(new Button("Button"), 1, 1);
innerPane2.add(new Label("  Label"), 2, 1);
innerPane2.add(new Button("Button"), 1, 2);
innerPane2.add(new Label("  Label"), 2, 2);
innerPane2.add(new Button("Button"), 1, 3);
innerPane2.add(new Label("  Label"), 2, 3);
GridPane.setMargin(innerPane2, new Insets(5,5,5,5));
outerPane.add(innerPane2, 1, 2);
outerPane.setAlignment(Pos.CENTER);

输出

在评论中删除任何进一步的混淆:)

于 2021-05-13T09:37:37.947 回答