Why can't I embed Ace Editor into WebView?

旧时模样 提交于 2019-12-12 01:03:42

问题


I am attempting to make a simple editor in JavaFX 2.2. I downloaded Ace Editor repository and created a test page which works fine when double clicked.

However, it does not work when I try to embed it into the WebView.

SSCCE:

package web;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.SceneBuilder;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPaneBuilder;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.scene.web.WebViewBuilder;
import javafx.stage.Stage;

public class EditorTrial extends Application{
    WebView webView;
    WebEngine engine;
    StackPane stack;
    Scene scene;


    @Override
    public void start(Stage primStage) throws Exception {
        stack = StackPaneBuilder
                .create()
                .alignment(Pos.CENTER)
                .build();

        webView = WebViewBuilder
                .create()
                .build();

        engine = webView.getEngine();
        engine.setJavaScriptEnabled(true);
        engine.load("/home/little/Downloads/AceEditor/ace-builds-master/MyTrial.html");
        stack.getChildren().add(webView);

        scene = SceneBuilder
                .create()
                .root(stack)
                .build();

        primStage.setScene(scene);
        primStage.sizeToScene();
        primStage.show();

    }

    public static void main(String[] args) {
        Application.launch("web.EditorTrial");
    }
}  

Can someone please tell me what is wrong?


回答1:


It works for me when the absolute file path : try

File f = new File("/home/little/Downloads/AceEditor/ace-builds-master/MyTrial.html");
String StrURL = f.toURI().toURL().toString(); 
engine.load(StrURL);


来源:https://stackoverflow.com/questions/19619126/why-cant-i-embed-ace-editor-into-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!