Tuesday, March 20, 2012

Create web browser with JavaFX 2.0 WebView

JavaFX 2.0 provide WebView, a full function web browser based on WebKit, an open source web browser engine. It supports Cascading Style Sheets (CSS), JavaScript, Document Object Model (DOM), and HTML5 features of rendering canvas and timed media playback.

JavaFX 2.0 WebView

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javafx_webview;

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

/**
*
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_Browser extends Application {

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

@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("java-buddy.blogspot.com");

WebView myBrowser = new WebView();
WebEngine myWebEngine = myBrowser.getEngine();
myWebEngine.load("http://java-buddy.blogspot.com/");

StackPane root = new StackPane();
root.getChildren().add(myBrowser);
primaryStage.setScene(new Scene(root, 640, 480));
primaryStage.show();
}
}



Next:
- Create custom browser class to embed WebView

3 comments:

  1. Very Nice Example...Thanks very much..Its Perfect

    ReplyDelete
  2. Hello, nice example..,
    I also try to open gmail using this browser example. When I compose an email, I try to attach a file from my computer, but this message appear

    "This file is 0 bytes, so it will not be attached."

    The same type message appear when attach in yahoo mail, are there any code must be added to the snippets or any other solution ?

    ReplyDelete
  3. Hello..nice tutorial...how Can I create web browser in javafx with linux??

    ReplyDelete