为什么我不能将Ace Editor嵌入WebView?

时间:2013-10-27 14:25:33

标签: java html javafx-2 javafx-webengine

我正在尝试在JavaFX 2.2中创建一个简单的编辑器。我下载了Ace Editor存储库并创建了一个测试页面,双击时工作正常。

但是,当我尝试将其嵌入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");
    }
}  

有人可以告诉我出了什么问题吗?

1 个答案:

答案 0 :(得分:-1)

当绝对文件路径时,它适用于我: 试试

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