我正在学习javafx,正在创建TodoList应用程序。 我想包括某些功能,例如文本样式,使用项目符号列表等,为此,我在应用程序中添加了HTMLEditor,用于存储html文件供WebView加载。 为了测试html文件的保存和加载,我已经保存了一个示例“ test.html”文件(该文件不在我的类路径中),并希望WebView加载它。 这是我的一些代码:
Main.fxml
Fxml Controller.java
public class Controller{
@FXML private WebView webView;
private WebEngine engine = webView.getEngine();
@FXML
public void initialize() throws IOException{
//code for some ArrayList initialization
engine.load("/home/jyotiproy/TodoOutput/test.html");
}
}
加载程序的Main.java
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
primaryStage.setTitle("Todo List");
primaryStage.setScene(new Scene(root, 1200, 600));
primaryStage.show();
primaryStage.setResizable(false);
}
public static void main(String[] args) {
launch(args);
}
}
我没有任何错误或异常。 “ test.html”的路径中没有错字,并且html编辑器可以正常工作并保存test.html,但WebView不会加载任何内容。 这是我的应用程序结构: