use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class LoadHtml 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 HTML");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<html><body><h1>Hello there!</h1></body></html>");
});
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class LoadHtmlThroughInterceptRequest method main.
public static void main(String[] args) {
InterceptUrlRequestCallback interceptCallback = params -> {
if (params.urlRequest().url().endsWith("?load-html")) {
byte[] bytes = "<html><body>Hello!</body></html>".getBytes();
UrlRequestJob job = params.newUrlRequestJob(UrlRequestJob.Options.newBuilder(HttpStatus.OK).addHttpHeader(HttpHeader.of("Content-Type", "text/html")).build());
job.write(bytes);
job.complete();
return InterceptUrlRequestCallback.Response.intercept(job);
}
return InterceptUrlRequestCallback.Response.proceed();
};
Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).addScheme(Scheme.HTTP, interceptCallback).build());
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Load Local Files");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("http://localhost?load-html");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class CustomProtocol method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).addScheme(Scheme.of(PROTOCOL), new InterceptCustomSchemeCallback()).build());
Browser browser = engine.newBrowser();
invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Custom Protocol Handler");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl(PROTOCOL + "://hello");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class DefaultZoomLevel 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("Change Default Zoom Level");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
engine.zoomLevels().defaultLevel(ZoomLevel.P_300);
browser.navigation().loadUrl("https://www.google.com");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class DisablePdfViewer method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Plugins plugins = engine.plugins();
// #docfragment "disabling-pdf-viewer"
plugins.settings().disablePdfViewer();
// #enddocfragment "disabling-pdf-viewer"
Browser browser = engine.newBrowser();
invokeLater(() -> {
// Display a Swing frame with embedded BrowserView.
showGui(browser);
// Now, if you load a PDF document, it will not be displayed in the
// PDF Viewer and will be downloaded instead.
browser.navigation().loadUrl("http://www.orimi.com/pdf-test.pdf");
});
}
Aggregations