Wednesday, March 21, 2012

Create custom browser class to embed WebView

Previous article demonstrate how to "Create web browser with JavaFX 2.0 WebView" by instancing a WebView object. It's modify to create a new class, MyBrowser, extends Region, and embed a WebView inside, such that we can easy customize our MyBrowser in the future.

Create custom class to embed WebView

package javafx_webview;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Region;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

* @web
public class JavaFX_Browser extends Application {

private Scene scene;
MyBrowser myBrowser;

* @param args the command line arguments
public static void main(String[] args) {

public void start(Stage primaryStage) {

myBrowser = new MyBrowser();
scene = new Scene(myBrowser, 640, 480);


class MyBrowser extends Region{

final String HOME = "";
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();

public MyBrowser(){



No comments:

Post a Comment