我正在尝试添加一个包含多个MeshView的组,这些MeshView从文件读取到borderlayout的中心。我正在使用FXML文件定义布局。我给中心AnchorPane一个fx:id“ centerPane”,给包含MeshViews的组一个fx:id“ centerGroup”。我没有收到任何错误,但是中间窗格的屏幕上没有任何显示。当我第一次开始手动创建MeshView时,我正在做类似的事情,它会出现在中央窗格中(但是后来我使用borderpane对象的setCenter方法(为此我还给它分配了fx:id名称)我可以从控制器代码中访问它。我将包括直接涉及到的fxml部分和下面的控制器中的行。如果有人可以帮助我弄清楚如何使Meshviews出现,我将非常感谢您的帮助。读了大部分JavaFX书籍,由于某种原因仍然对此感到困惑。谢谢。
从FXML文件:
<center>
<VBox prefHeight="400.0" prefWidth="640.0">
<children>
<AnchorPane fx:id="centerPane" maxHeight="-1.0" maxWidth="-1.0"
prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
<children>
<Group fx:id="centerGroup" />
</children>
</AnchorPane>
</children>
</VBox>
</center>
来自控制器文件的行:
@FXML
private AnchorPane centerPane;
@FXML
private Group centerGroup;
(inside of a for loop I add the meshviews from an array list into the group)
for( - ; - ; - ){
centerGroup.getChildren().add(meshViews[i]);
}
PerspectiveCamera camera = new PerspectiveCamera(false);
PointLight redLight = new PointLight();
redLight.setColor(Color.RED);
PointLight greenLight = new PointLight();
greenLight.setColor(Color.GREEN);
( I have tried all three below. middle one gave duplicate child error. )
//borderPane.setCenter(centerGroup);
//centerPane.getChildren().addAll(centerGroup, redLight, greenLight);
centerPane.getChildren().addAll(redLight, greenLight);
我相信足够的代码可以描绘出我要修复的内容。我将附上gui的图片,以显示在代码运行时,并且我将其打印输出到控制台时,从文件读取的meshviews的数量和数量是正确的,屏幕上没有任何显示。感谢您的帮助。
答案 0 :(得分:0)
您需要将相机添加到舞台
yourStage.setCamera(camera);
将相机添加到您的组
centerPane.getChildren().add(camera);