use of com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED 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.RenderingMode.HARDWARE_ACCELERATED in project JxBrowser-Examples by TeamDev-IP.
the class FindText 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);
JTextField searchField = new JTextField("Text to find");
searchField.addActionListener(e -> browser.textFinder().find(searchField.getText(), findResult -> System.out.println("Matches found: " + findResult.numberOfMatches())));
JFrame frame = new JFrame("Find Text");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(searchField, BorderLayout.NORTH);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("https://www.google.com");
}
Aggregations