use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class ContentListening method main.
public static void main(String[] args) {
// #docfragment "engine-creation"
Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).build());
Browser browser = engine.newBrowser();
// #enddocfragment "engine-creation"
// #docfragment "embed-browser-view"
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Content Listening");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
// #enddocfragment "embed-browser-view"
// #docfragment "inject-js"
browser.set(InjectJsCallback.class, params -> {
Frame frame = params.frame();
String window = "window";
JsObject jsObject = frame.executeJavaScript(window);
if (jsObject == null) {
throw new IllegalStateException(format("'%s' JS object not found", window));
}
jsObject.putProperty("java", new JavaObject());
return Response.proceed();
});
// #enddocfragment "inject-js"
// #docfragment "frame-load-finished"
browser.navigation().on(FrameLoadFinished.class, event -> {
String javaScript = load("observer.js");
event.frame().executeJavaScript(javaScript);
});
// #enddocfragment "frame-load-finished"
// #docfragment "load-page"
String html = load("index.html");
String base64Html = Base64.getEncoder().encodeToString(html.getBytes(UTF_8));
String dataUrl = "data:text/html;base64," + base64Html;
browser.navigation().loadUrl(dataUrl);
// #enddocfragment "load-page"
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class AuthenticationDialog method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Hello World");
engine.network().set(AuthenticateCallback.class, createAuthenticationPopup(frame));
frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 500);
frame.setVisible(true);
browser.navigation().loadUrl("http://httpbin.org/basic-auth/user/passwd");
});
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class BrowserViewInJInternalFrame method createInternalFrame.
private static JInternalFrame createInternalFrame(String title, String url, int offset) {
// To display BrowserView in Swing JInternalFrame, the engine must be configured
// with the OFF_SCREEN rendering mode. In case of the HARDWARE_ACCELERATED rendering
// mode we will get a well known issue with mixing heavyweight and lightweight
// components. Read more about this limitation at
// https://jxbrowser-support.teamdev.com/docs/guides/browser-view.html#mixing-heavyweight-and-lightweight
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browser = engine.newBrowser();
browser.navigation().loadUrl(url);
BrowserView view = BrowserView.newInstance(browser);
JInternalFrame frame = new JInternalFrame(title, true);
frame.setContentPane(view);
frame.setLocation(100 + offset, 100 + offset);
frame.setSize(400, 400);
frame.setVisible(true);
return frame;
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class SuppressMouse method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
browser.set(PressMouseCallback.class, params -> {
if (params.event().keyModifiers().isShiftDown()) {
return PressMouseCallback.Response.proceed();
}
return PressMouseCallback.Response.suppress();
});
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Suppress the Mouse Pressed event");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(500, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<button onclick=\"clicked()\">click holding shift</button>" + "<script>function clicked() {alert('clicked');}</script>");
});
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class WebSocket method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Web Socket");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("https://www.websocket.org/echo.html");
}
Aggregations