一旦点击了帮助按钮,我正在寻找一种在不同阶段显示html文件的方法。
public void handleButtonAction(ActionEvent event) throws IOException {
if (event.getSource() == help) {
stage = (Stage) help.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("help.fxml"));
WebView browser = new WebView();
Scene helpScene = new Scene(root);
Stage helpStage = new Stage();
helpStage.setTitle("Help Menu");
helpStage.setScene(helpScene);
URL url = getClass().getResource("readme.html");
browser.getEngine().load(url.toExternalForm());
helpStage.show();
}
}
答案 0 :(得分:5)
您的代码没问题,只是您忘记将webview添加到场景中,执行
((Pane) helpScene.getRoot()).getChildren().add(browser);