0
爲什麼佈局參數需要聲明爲最終?JavaFX傳遞佈局作爲參數
如下:
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Login form");
BorderPane borderLayout = new BorderPane();
borderLayout.setCenter(login(borderLayout));
Scene scene = new Scene(borderLayout, 300, 275);
primaryStage.setScene(scene);
primaryStage.show();
}
private GridPane login(final BorderPane rootLayout){ //<<--
// CODE
return grid;
}
編輯:最後的BorderLayout shud've一直BorderPane。
查看這裏的相同問題的答案http://stackoverflow.com/questions/4930114/why-declare-a-function-argument-to-be-final – csmckelvey
爲什麼你會使用'BorderLayout'?另外,你是否意識到你正在通過'BorderPane'實例登錄方法而不是'BorderLayout'實例 –
@ csmckelvey謝謝!當然有道理,但我在登錄方法裏面做的實際上是在做rootLayout.setCenter(otherMethod(rootLayout)),或者這不是你的意思嗎?因爲它確實不會限制我這樣做。 – Taerus