use of com.teamdev.jxbrowser.navigation.Navigation 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.navigation.Navigation 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");
}
use of com.teamdev.jxbrowser.navigation.Navigation in project JxBrowser-Examples by TeamDev-IP.
the class GetHtml 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("Get HTML");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
});
Navigation navigation = browser.navigation();
// Add the callback for waiting till the page is loaded.
navigation.on(FrameLoadFinished.class, event -> {
if (event.frame().isMain()) {
browser.mainFrame().ifPresent(frame -> System.out.println("HTML = " + frame.html()));
}
});
navigation.loadUrl("https://www.teamdev.com/jxbrowser#features");
}
Aggregations