JavaFX WebEngine load html content

Description

JavaFX WebEngine load html content

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class Main extends Application {
   public static void main(String[] args) {
      Application.launch(args);//ww w .j  ava2 s.c o  m
   }

   @Override
   public void start(Stage primaryStage) {
      VBox vb = new VBox();
      vb.setId("root");

      WebView browser = new WebView();
      WebEngine engine = browser.getEngine();

      engine.loadContent("<html><body><b>demo2s.com</b></body></html>");

      vb.setPadding(new Insets(30, 50, 50, 50));
      vb.setSpacing(10);
      vb.setAlignment(Pos.CENTER);
      vb.getChildren().addAll(browser);

      Scene scene = new Scene(vb);
      primaryStage.setScene(scene);
      primaryStage.show();
   }
}



PreviousNext

Related