设置具有多个节点的javafx场景

时间:2013-08-24 07:33:45

标签: javafx-2 nodes scene

我正在尝试设置我的javafx场景,但我失败了。 基本上我想要做的就是附上照片。

enter image description here

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

我不想使用FXML。

你们可以推荐如何进行这种设置。

2 个答案:

答案 0 :(得分:0)

JavaFx SceneBuilder是一个很好的工具,可以像你想要的那样创建Layouts。看看官方website。该工具创建一个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频道。

答案 1 :(得分: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);

Output

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