use of com.teamdev.jxbrowser.engine.Engine 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.engine.Engine 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.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class BrowserViewInJFxPanel method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browser = engine.newBrowser();
JFXPanel panel = new JFXPanel();
Platform.runLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
panel.setScene(new Scene(view));
});
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("JavaFX BrowserView in Swing app");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(panel, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});
browser.navigation().loadUrl("https://www.google.com");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class BrowserViewInTabPane method start.
@Override
public void start(Stage primaryStage) {
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browserOne = engine.newBrowser();
browserOne.navigation().loadUrl("https://www.google.com");
BrowserView viewOne = BrowserView.newInstance(browserOne);
Tab tabOne = new Tab("Browser One");
tabOne.setContent(viewOne);
Browser browserTwo = engine.newBrowser();
browserTwo.navigation().loadUrl("https://www.teamdev.com");
BrowserView viewTwo = BrowserView.newInstance(browserTwo);
Tab tabTwo = new Tab("Browser Two");
tabTwo.setContent(viewTwo);
TabPane tabPane = new TabPane();
tabPane.getTabs().add(tabOne);
tabPane.getTabs().add(tabTwo);
Group root = new Group();
Scene scene = new Scene(root, 700, 500);
BorderPane pane = new BorderPane();
pane.prefHeightProperty().bind(scene.heightProperty());
pane.prefWidthProperty().bind(scene.widthProperty());
pane.setCenter(tabPane);
root.getChildren().add(pane);
primaryStage.setTitle("Browser View In Tab Pane");
primaryStage.setScene(scene);
primaryStage.show();
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class JavaFxBrowserView method start.
@Override
public void start(final Stage primaryStage) {
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browser = engine.newBrowser();
BrowserView view = BrowserView.newInstance(browser);
Scene scene = new Scene(new BorderPane(view), 700, 500);
primaryStage.setTitle("JavaFx BrowserView");
primaryStage.setScene(scene);
primaryStage.show();
browser.navigation().loadUrl("https://www.google.com");
}
Aggregations