use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class BitmapToSwtImage method main.
public static void main(String[] args) {
Display display = new Display();
try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
Browser browser = engine.newBrowser();
// Resize browser to the required dimension
browser.resize(1024, 768);
// Load the required web page and wait until it is loaded completely
browser.navigation().loadUrlAndWait("https://www.google.com");
Bitmap bitmap = browser.bitmap();
// Convert the bitmap to org.eclipse.swt.graphics.Image
Image image = BitmapImage.toToolkit(display, bitmap);
// Save the image to a PNG file
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { image.getImageData() };
loader.save("bitmap.png", SWT.IMAGE_PNG);
}
display.dispose();
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class DefaultOpenPopupCallback method on.
@Override
public Response on(Params params) {
Browser browser = params.popupBrowser();
try {
Display display = Display.getDefault();
display.asyncExec(() -> {
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
BrowserView view = BrowserView.newInstance(shell, browser);
updateBounds(shell, view, params.initialBounds());
shell.addDisposeListener(event -> {
if (!browser.isClosed()) {
asyncExec(shell, browser::close);
}
});
browser.on(TitleChanged.class, event -> asyncExec(shell, () -> shell.setText(event.title())));
browser.on(BrowserClosed.class, event -> asyncExec(shell, shell::dispose));
browser.on(UpdateBoundsRequested.class, event -> asyncExec(shell, () -> updateBounds(shell, view, event.bounds())));
view.setVisible(true);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
});
} catch (SWTException ignore) {
Response.proceed();
}
return Response.proceed();
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class SwtBrowserView method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("SWT BrowserView");
shell.setLayout(new GridLayout());
com.teamdev.jxbrowser.view.swt.BrowserView view = BrowserView.newInstance(shell, browser);
view.setSize(700, 500);
shell.pack();
shell.open();
browser.navigation().loadUrl("https://www.google.com");
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
engine.close();
display.dispose();
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class XPath method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Evaluate XPath");
frame.getContentPane().add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
Navigation navigation = browser.navigation();
navigation.on(FrameLoadFinished.class, event -> event.frame().document().flatMap(Document::documentElement).ifPresent(element -> {
try {
XPathResult result = element.evaluate("count(//div)");
if (result.isNumber()) {
System.out.println("Result: " + result.asNumber());
}
} catch (XPathException e) {
System.out.println(e.getMessage());
}
}));
navigation.loadUrl("https://www.teamdev.com/jxbrowser");
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class ZoomLevel 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 Zoom Level");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
// Listen to the zoom changed events.
ZoomLevels levels = engine.zoomLevels();
levels.on(ZoomLevelChanged.class, event -> System.out.println("Url: " + event.host() + "\n" + "Zoom level: " + event.level()));
Navigation navigation = browser.navigation();
navigation.on(FrameLoadFinished.class, event -> {
if (event.frame().isMain()) {
browser.zoom().level(com.teamdev.jxbrowser.zoom.ZoomLevel.P_200);
}
});
navigation.loadUrl("https://www.google.com");
}
Aggregations