use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class JsAccessibleMethod method main.
public static void main(String[] args) {
try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
Browser browser = engine.newBrowser();
browser.mainFrame().ifPresent(frame -> {
JsObject jsObject = frame.executeJavaScript("window");
if (jsObject != null) {
// Inject Java object into JavaScript and associate it
// with the "window.java" JavaScript property.
jsObject.putProperty("java", new JavaObject());
}
// Call the annotated public method of the injected Java object from JS.
frame.executeJavaScript("window.java.sayHello()");
});
}
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class JsConsoleEvents 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("JS Console Listener");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.on(ConsoleMessageReceived.class, event -> {
ConsoleMessage consoleMessage = event.consoleMessage();
System.out.printf("Level: %s\nMessage: %s%n", consoleMessage.level().name(), consoleMessage.message());
});
browser.mainFrame().ifPresent(frame -> frame.executeJavaScript("console.error(\"Error message\");"));
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class LoadUrl 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("Load URL");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("https://www.google.com");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class CustomCss 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("Custom CSS");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.set(InjectCssCallback.class, params -> InjectCssCallback.Response.inject("body { background-color: orange; }"));
browser.navigation().loadUrl("about:blank");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class DispatchKeyEvents 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("Dispatch key event");
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
engine.close();
}
});
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.add(view);
frame.setSize(800, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
loadHtmlAndWait(browser, HTML);
dispatchKey(browser, 'h');
dispatchKey(browser, 'i');
}
Aggregations