Reputation: 2214
I tried to follow the instruction describe here: http://docs.oracle.com/javafx/2.0/webview/jfxpub-webview.htm to display a web page on javafx 2.1, but web page does not display although I've already signed my application using javafx-ant tool (this link mentions about signing javafx application How can I display a javascript webpage inside a WebView in JavaFx 2.0 in Browser).
I can view the web page when running javafx on browser, but can't view it when running application as java stand alone application.
Here's the code:
browser control:
public class Browser extends Region {
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
public Browser() {
//apply the styles
getStyleClass().add("browser");
// load the web page
webEngine.load("http://www.google.com");
//add the web view to the scene
getChildren().add(browser);
}
//...
}
Display it:
Stage stage = new Stage();
stage.setTitle("Web View");
Scene scene = new Scene(new Browser(),590,400, Color.web("#666970"));
stage.setScene(scene);
scene.getStylesheets().add("/com/sai/javafx/calendar/styles/BrowserToolbar.css");
stage.show();
Any idea would be highly appreciated.
Upvotes: 1
Views: 4010
Reputation: 2214
As far as I know, the only way to solve my problem is loading the .html file locally (can't load web page from other domain, and this html file must not refer to any external link)
public Browser() {
//apply the styles
getStyleClass().add("browser");
// load the web page
final URL urlHello = Browser.class.getResource("sample.html");
webEngine.load(urlHello.toExternalForm());
}
Display it:
Stage stage = new Stage();
stage.setTitle("Web View");
Scene scene = new Scene(new Browser(),590,400, Color.web("#666970"));
stage.setScene(scene);
scene.getStylesheets().add("/com/sai/javafx/calendar/styles/BrowserToolbar.css");
stage.show();
Upvotes: 0
Reputation: 159416
Here is a sample app:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebViewSample extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(final Stage primaryStage) {
final WebView webView = new WebView();
webView.getEngine().load("http://docs.oracle.com/javafx/");
primaryStage.setScene(new Scene(webView));
primaryStage.show();
}
}
Here is what it looks like in a browser, the inner scrollpane is the JavaFX WebView rendered browser and the outer text is the html page embedding the JavaFX WebView.
To run it I used NetBeans nightly build, JavaFX 2.2b4, JDK7u6ea, Win7, IE9.
Steps in NetBeans were:
Upvotes: 2