说我遇到的问题是,当我试图瓷砖添加到面板边框的中央,然后是边框面板添加到根面板边框的中心,走线远离正确。JavaFX的节点对准BorderPanes
这里是我创建了一个主或“根”窗格中,我命名为mainPane
。然后,我创建了bottomPane
和centerPane
举行,最终将被添加到mainPane
底部和中心项目:
BorderPane mainPane = new BorderPane();
BorderPane bottomPane = new BorderPane();
BorderPane centerPane = new BorderPane();
Button quitButton = new Button("Quit Game");
bottomPane.setRight(quitButton);
Text gameWinLabel = new Text();
gameWinLabel.setText("You win!");
gameWinLabel.setFont(Font.font("Times New Roman", 50));
gameWinLabel.setVisible(false);
bottomPane.setCenter(gameWinLabel);
然后我写了会产生记忆游戏瓷砖代码:
char c = 'A';
List<Tile> tiles = new ArrayList<>();
for (int i = 0; i < NUM_OF_PAIRS; i++) {
tiles.add(new Tile(String.valueOf(c)));
tiles.add(new Tile(String.valueOf(c)));
c++;
}
Collections.shuffle(tiles);
for (int i = 0; i < tiles.size(); i++) {
Tile tile = tiles.get(i);
tile.setTranslateX(100 * (i % NUM_PER_ROW));
tile.setTranslateY(100 * (i/NUM_PER_ROW));
centerPane.getChildren().add(tile);
}
最后,我停住了容器窗格mainPane
:
mainPane.setBottom(bottomPane);
mainPane.setCenter(centerPane);
这是当前欧输入:
最终目标是让游戏集中在mainPane
的中心。
在此先感谢您的任何建议!
你可能会更好使用[GridPane(https://docs.oracle.com/javase/8/javafx/api/javafx/scene/layout/GridPane.html)为你的“根”这样你的只使用一个窗格并可以对齐内容。如果你想要更多的信息,我可以提出一个答案,并给你一些代码。 – TravisF
@TravisF一个例子会很棒!我很难与什么窗格绑定。 – wpursell