Javafx在加载网页时添加或删除splitpane面板

时间:2016-10-20 05:36:26

标签: javafx webview jsplitpane

我想在加载splitPane删除pnLoad并加载完成时加入url,我添加了pnLoad回来但是在完成后添加了更多pnLoad而不是只有一个。请帮助我

private void webView() {
    webEngine = browser.getEngine();
    webEngine.load(url);

    try {
        FXMLLoader fxmlLoader = new FXMLLoader();
        Pane pnLoad = FXMLLoader.load(getClass().getResource("Detail.fxml"));
    } catch (IOException ex) {
        Logger.getLogger(BrowserController.class.getName()).log(Level.SEVERE, null, ex);
    }

    webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) -> {
        switch (newValue) {
            case RUNNING:
                if (pnLoad.isVisible()) {
                    spBrowser.getItems().remove(pnLoad);
                }
                break;
            case SUCCEEDED:
                try {
                    spBrowser.getItems().add(pnLoad);
                    spBrowser.setDividerPositions(0.6);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                break;
        }
    });
}

0 个答案:

没有答案