问题
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