Reputation: 21
is it possible to enable webSocket for javaFx webView, so I can use the chat function of a Url to receive and send messages which is loaded by webView webEngine?
Upvotes: 0
Views: 1374
Reputation: 159486
Yes, JavaFX WebView supports web sockets.
Here is a sample JavaFX program which loads a web page with web socket features and utilizes them in a WebView.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebsocketClientExample extends Application {
@Override
public void start(Stage stage) throws Exception {
WebView webview = new WebView();
webview.getEngine().load(
"http://demos.kaazing.com/echo/index.html"
);
webview.setPrefSize(640, 600);
stage.setScene(new Scene(webview));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Upvotes: 1