我想在JavaFX中製作一個簡單的遊戲(這是一個學校工作),並且我試圖用板清理面板,然後重新繪製它。我已經嘗試了很多方法,而且這是我發現的唯一一個可以刪除所有棋盤(可視化)的部分,而不會創建顯示已經被刪除但仍然顯示的棋子的視覺錯誤。在JavaFX中清理gridPane並維護Grid線
所以我聲明gridPane
這樣的:
private GridPane gridPecas;
@Override
public void start(Stage primaryStage)
{
gridPecas = new GridPane();
gridPecas.setGridLinesVisible(true);
paintBoard();
// rest of the code to create and paint the Stage
}
private void paintBoard()
{
gridPecas.getChildren().clear();
// Code to fill the board with ImageView and Images of the pieces
}
這種方法的問題是,當 「gridPecas.getChildren()清除();」被稱爲我只是從鬆散網格線。
我該如何解決這個問題?
感謝您的回答,但我剛剛找到了完美的解決方案xD而不是「gridPecas.getChildren()。clear();」我只是在for循環中這樣做:「gridPecas.getChildren()。removeAll(pecasFX [i] [j]);」因此,當閱讀這篇文章時,它會從網格中刪除它,並且,由於原始的「填充板」代碼,他有一個新的邊界清理和更新。 – aliasbody