以下是我在home.fxml
中心加载borderPane
的主页面控制器:
MainController.java
public class MainController implements Initializable {
@FXML private BorderPane borderPane;
@Override
public void initialize(URL location, ResourceBundle resources) {
try {
Connection connection = SqlConnection.dbConnector();
//JDBC connection initial check
if (connection != null) {
newLoginStage();
connection.close();
}
goToHome();
} catch (Exception e) {
e.printStackTrace();
}
}
//ToolBar Methods
@FXML public void goToHome() throws Exception {
toolBarButtonClick(homeTB, "home.fxml");
}
@FXML private void logout() throws Exception {
Stage stage = (Stage) borderPane.getScene().getWindow();
stage.hide();
newLoginStage();
stage.show();
}
@FXML public void exit() throws Exception {
}
private void toolBarButtonClick(Button button, String fxml) throws Exception {
button.setDisable(true);
}
private void newMainContent(String fxml) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource(fxml));
borderPane.setCenter(fxmlLoader.load());
}
HomeController.java
public class HomeController implements Initializable {
@FXML
private BorderPane borderPane;
@Override
public void initialize(URL location, ResourceBundle resources) {
mainContent = new MainContent(borderPane);
BorderPane parentBorderPane = (BorderPane)borderPane.getParent();
parentBorderPane.setLeft(null);
}
我打算在主页面中隐藏borderPane
的左侧部分,但我无法通过borderPane.getParent()
中的HomeController.java
获取父级。