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();
Platform.runLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
Stage stage = new Stage();
StackPane root = new StackPane();
Scene scene = new Scene(root);
root.getChildren().add(view);
stage.setScene(scene);
updateBounds(stage, params.initialBounds());
stage.setOnCloseRequest(event -> browser.close());
browser.on(TitleChanged.class, event -> Platform.runLater(() -> stage.setTitle(event.title())));
browser.on(BrowserClosed.class, event -> Platform.runLater(stage::close));
browser.on(UpdateBoundsRequested.class, event -> Platform.runLater(() -> updateBounds(stage, event.bounds())));
stage.show();
});
return Response.proceed();
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class AuthenticationDialog 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("Hello World");
engine.network().set(AuthenticateCallback.class, createAuthenticationPopup(frame));
frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 500);
frame.setVisible(true);
browser.navigation().loadUrl("http://httpbin.org/basic-auth/user/passwd");
});
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class BitmapToSwingImage method main.
public static void main(String[] args) throws IOException {
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 java.awt.image.BufferedImage
BufferedImage bufferedImage = BitmapImage.toToolkit(bitmap);
// Save the image to a PNG file
ImageIO.write(bufferedImage, "PNG", new File("bitmap.png"));
}
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class BrowserViewInJInternalFrame method createInternalFrame.
private static JInternalFrame createInternalFrame(String title, String url, int offset) {
// To display BrowserView in Swing JInternalFrame, the engine must be configured
// with the OFF_SCREEN rendering mode. In case of the HARDWARE_ACCELERATED rendering
// mode we will get a well known issue with mixing heavyweight and lightweight
// components. Read more about this limitation at
// https://jxbrowser-support.teamdev.com/docs/guides/browser-view.html#mixing-heavyweight-and-lightweight
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browser = engine.newBrowser();
browser.navigation().loadUrl(url);
BrowserView view = BrowserView.newInstance(browser);
JInternalFrame frame = new JInternalFrame(title, true);
frame.setContentPane(view);
frame.setLocation(100 + offset, 100 + offset);
frame.setSize(400, 400);
frame.setVisible(true);
return frame;
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class SuppressMouse method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
browser.set(PressMouseCallback.class, params -> {
if (params.event().keyModifiers().isShiftDown()) {
return PressMouseCallback.Response.proceed();
}
return PressMouseCallback.Response.suppress();
});
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Suppress the Mouse Pressed event");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(500, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<button onclick=\"clicked()\">click holding shift</button>" + "<script>function clicked() {alert('clicked');}</script>");
});
}
Aggregations