Basic browser in java fx


/ Published in: Java
Save to your folder(s)

don't forget to add jfxrt.jar to class path


Copy this code and paste it in your HTML
  1. package main;
  2.  
  3. import javafx.application.Application;
  4. import javafx.scene.Scene;
  5. import javafx.scene.layout.StackPane;
  6. import javafx.scene.web.WebEngine;
  7. import javafx.scene.web.WebView;
  8. import javafx.stage.Stage;
  9.  
  10. /**
  11. *
  12. * @web http://java-buddy.blogspot.com/
  13. */
  14. public class Request extends Application {
  15.  
  16. /**
  17.   * @param args the command line arguments
  18.   */
  19. public static void main(String[] args) {
  20. launch(args);
  21. }
  22.  
  23. @Override
  24. public void start(Stage primaryStage) {
  25. primaryStage.setTitle("facebook.com");
  26.  
  27. WebView myBrowser = new WebView();
  28. WebEngine myWebEngine = myBrowser.getEngine();
  29. myWebEngine.load("https://google.com");
  30.  
  31. StackPane root = new StackPane();
  32. root.getChildren().add(myBrowser);
  33. primaryStage.setScene(new Scene(root, 640, 480));
  34. primaryStage.show();
  35. }
  36. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.