use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class RedirectLoggingToFile method main.
public static void main(String[] args) {
Path loggingDir;
try {
loggingDir = Files.createTempDirectory("jxbrowser-logs");
} catch (IOException e) {
throw new RuntimeException("Failed to create a temporary directory", e);
}
Path loggingFile = loggingDir.resolve("jxbrowser.log");
System.setProperty("jxbrowser.logging.file", loggingFile.toAbsolutePath().toString());
System.out.println("Log file path: " + loggingFile.toAbsolutePath());
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Redirect Logging To File");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("https://www.google.com");
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class SelectionAsHtml 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);
JButton button = new JButton("Get Selected HTML");
button.addActionListener(e -> browser.mainFrame().ifPresent(frame -> SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(view, frame.selectionAsHtml(), "Selected HTML", JOptionPane.PLAIN_MESSAGE))));
JFrame frame = new JFrame("Get Selected HTML");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(button, BorderLayout.NORTH);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("https://www.teamdev.com/jxbrowser#features");
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class SpellCheckEvents 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("Spell Check Events");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.on(SpellCheckCompleted.class, event -> event.results().forEach(checkResult -> {
System.out.println("Error start index: " + checkResult.location());
System.out.println("Error length: " + checkResult.length());
}));
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<html><body>" + "<textarea autofocus rows='20' cols='30'>Smple text with mitake.</textarea>" + "</body></html>");
});
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class SslCertificateVerifier 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("SSL Certificate Verifier");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
engine.network().set(VerifyCertificateCallback.class, params -> {
String host = params.host().value();
System.out.println("Verifying certificate for " + host + "...");
// Reject SSL certificate for all "google.com" hosts.
if (host.contains("google.com")) {
return Response.invalid(AUTHORITY_INVALID);
} else {
return Response.valid();
}
});
browser.navigation().loadUrl("https://www.google.com");
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class DomForm method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("DOM HTML Form");
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.findElementByName("firstName").ifPresent(firstName -> firstName.putAttribute("value", "John"));
element.findElementByName("lastName").ifPresent(lastName -> lastName.putAttribute("value", "Doe"));
}));
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<html><body><form name=\"myForm\">" + "First name: <input type=\"text\" name=\"firstName\"/><br/>" + "Last name: <input type=\"text\" name=\"lastName\"/><br/>" + "<input type=\"button\" value=\"Save\"/>" + "</form></body></html>");
});
}
Aggregations