Java Reference
In-Depth Information
You want to embed HTML5 content in the form of a Scalable Vector Graphics (SVG)
file into a JavaFX application.
Solution
Create a JavaFX based-application containing an analog clock that was created as an
SVG file. Use JavaFX's WebView API to render HTML5 content in your application.
The following source code is a JavaFX application that displays an animated ana-
log clock. The application will load an SVG file named clock3.svg and display the
contents onto the JavaFX Scene graph:
package org.java8recipes.chapter17.recipe17_02;
import java.net.URL;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
/**
*
* @author cdea
*/
public class DisplayHtml5Content extends Application {
private Scene scene;
@Override public void start(Stage stage) {
// create the scene
stage.setTitle("Chapter 17-2 Display Html5
Content");
final WebView browser = new WebView();
URL url = getClass().getResource("clock3.svg");
browser.getEngine().load(url.toExternalForm());
scene = new Scene(browser,590,400, Color.rgb(0,
0, 0, .80));
stage.setScene(scene);
stage.show();
}
Search WWH ::




Custom Search