import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;

public class WebViewEmojiTest extends Application{

    @Override
    public void init() throws Exception {
Font font = Font.font("Apple Color Emoji");
System.out.println("font-name:"+font.getFamily());
    }
    
@Override
public void start(Stage primaryStage) throws Exception {
WebView webView = new WebView();
SplitPane root = new SplitPane();
root.getItems().add(webView);
root.getItems().add(new VBox(
new Label("😄EMOJI"),
new Label("EMOJI😄")
));

webView.getEngine().documentProperty().addListener((ob, oldValue, newValue)->{
// Workaround for problem with loadContent() method not handling surrogate pairs correctly.
JSObject body = (JSObject)webView.getEngine().executeScript("document.body");
body.setMember(
"innerHTML",
testHtmlFragment
);
});

Scene scene = new Scene(root, 600, 600);
primaryStage.setScene(scene);
primaryStage.show();

webView.getEngine().loadContent(html);
}

public static void main(String[] args) {
Application.launch(args);
}

String html = "<html>\n" +
"<head>\n" +
"</head>\n" +
"</html>";

String testHtmlFragment =
"<h2>Error case</h2>" +
"<div>😄EMOJI</div>" +
"<div>EMOJI😄</div>" +
"<div><button>😄EMOJI</button></div>" +
"<div><button>EMOJI😄</button></div>" +
"<textarea>😄EMOJI\nEMOJI😄</textarea>" +
"<h2>Workarround</h2>" +
"<div><span>😄</span>EMOJI</div>"+
"<div>EMOJI<span>😄</span></div>"+
"<div><button><span>😄</span>EMOJI</button></div>"+
"<div><button>EMOJI<span>😄</span></button></div>"
;
}
