use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class DomMouseEvents method main.
public static void main(String[] args) {
EngineOptions options = EngineOptions.newBuilder(HARDWARE_ACCELERATED).build();
Engine engine = Engine.newInstance(options);
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("DOM Mouse Event Listener");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
loadHtmlAndWait(browser);
findButton(browser).ifPresent(element -> {
element.addEventListener(MOUSE_DOWN, DomMouseEvents::printEventDetails, false);
element.addEventListener(MOUSE_UP, DomMouseEvents::printEventDetails, false);
element.addEventListener(MOUSE_OVER, DomMouseEvents::printEventDetails, false);
});
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class DomQuerySelector 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("DOM Query Selector");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().on(FrameLoadFinished.class, event -> event.frame().document().flatMap(Document::documentElement).ifPresent(element -> element.findElementsByCssSelector("p").forEach(paragraph -> System.out.println("innerHTML " + paragraph.innerHtml()))));
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<html><body><div id='root'>" + "<p>paragraph1</p>" + "<p>paragraph2</p>" + "<p>paragraph3</p>" + "</div></body></html>");
});
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class DomSelectOption 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("DOM Select Option");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().on(FrameLoadFinished.class, event -> browser.mainFrame().flatMap(Frame::document).flatMap(Document::documentElement).flatMap(element -> element.findElementById("select-tag")).ifPresent(selectElement -> {
Object[] options = ((SelectElement) selectElement).options().toArray();
((OptionElement) options[2]).select();
System.out.println(selectElement.innerHtml());
}));
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<html><body><select id='select-tag'>\n" + " <option value=\"volvo\">Volvo</option>\n" + " <option value=\"saab\">Saab</option>\n" + " <option value=\"opel\">Opel</option>\n" + " <option value=\"audi\">Audi</option>\n" + "</select></body></html>");
});
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class DownloadFile 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("Download File");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.set(StartDownloadCallback.class, (params, tell) -> {
params.download().on(DownloadFinished.class, event -> System.out.println("File downloaded!"));
tell.download(createTempDirectory().toAbsolutePath());
});
browser.navigation().loadUrl(URL_TO_DOWNLOAD);
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class SwingFullScreen 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("Swing Full Screen Mode");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
FullScreenHandler fullScreenHandler = new FullScreenHandler(frame, view);
browser.on(FullScreenEntered.class, event -> fullScreenHandler.onFullScreenEnter());
browser.on(FullScreenExited.class, event -> fullScreenHandler.onFullScreenExit());
});
browser.navigation().loadUrl("http://www.quirksmode.org/html5/tests/video.html");
}
Aggregations