在容器

时间:2017-03-14 08:57:16

标签: java javafx fxml

以下是我在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获取父级。

0 个答案:

没有答案