use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-QuickStart by TeamDev-IP.
the class HelloWorld method start.
@Override
public void start(Stage primaryStage) {
// Initialize Chromium.
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
// Load the required web page.
browser.navigation().loadUrl("https://html5test.com");
// Create and embed JavaFX BrowserView component to display web content.
BrowserView view = BrowserView.newInstance(browser);
Scene scene = new Scene(new BorderPane(view), 1280, 800);
primaryStage.setTitle("JxBrowser JavaFX");
primaryStage.setScene(scene);
primaryStage.show();
// Shutdown Chromium and release allocated resources.
primaryStage.setOnCloseRequest(event -> engine.close());
}
use of com.teamdev.jxbrowser.browser.Browser in project convertigo by convertigo.
the class C8oBrowser method init.
private void init(Engine browserContext) {
setLayout(new FillLayout());
browserView = BrowserView.newInstance(this, browserContext.newBrowser());
threadSwt = getDisplay().getThread();
Observer<Event> observer = ev -> {
if (!useExternalBrowser) {
return;
}
try {
Element elt = (Element) ev.target().get();
if (!elt.nodeName().equalsIgnoreCase("a")) {
return;
}
String href = elt.attributes().get("href");
if (!href.startsWith("http")) {
String url = elt.document().baseUri();
if (href.startsWith("/")) {
href = url.replaceFirst("(https?://.*?)/.*", "$1" + href);
} else {
href = url.replaceFirst("(https?://.*/).*", "$1" + href);
}
}
if (href.matches("https?://.*")) {
com.twinsoft.convertigo.engine.Engine.logStudio.info("Internal browser open link with the default browser: " + href);
Program.launch(href);
ev.preventDefault();
}
} catch (Exception e) {
}
};
getBrowser().mainFrame().get().document().get().addEventListener(EventType.CLICK, observer, false);
getBrowser().navigation().on(FrameLoadFinished.class, event -> {
event.frame().document().get().addEventListener(EventType.CLICK, observer, false);
});
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class BrowserViewInJTabbedPane method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browserOne = engine.newBrowser();
Browser browserTwo = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
JTabbedPane pane = new JTabbedPane();
pane.addTab("Google", BrowserView.newInstance(browserOne));
pane.addTab("TeamDev", BrowserView.newInstance(browserTwo));
JFrame frame = new JFrame("Browser View In JTabbed Pane");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(pane, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browserOne.navigation().loadUrl("https://www.google.com");
browserTwo.navigation().loadUrl("https://www.teamdev.com");
}
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();
invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame();
frame.add(view, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
invokeLater(browser::close);
}
});
updateBounds(frame, params.initialBounds());
browser.on(TitleChanged.class, event -> invokeLater(() -> frame.setTitle(event.title())));
browser.on(BrowserClosed.class, event -> invokeLater(() -> {
frame.setVisible(false);
frame.dispose();
}));
browser.on(UpdateBoundsRequested.class, event -> invokeLater(() -> updateBounds(frame, event.bounds())));
frame.setVisible(true);
});
return Response.proceed();
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class SwingBrowserView 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("Swing BrowserView");
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");
}
Aggregations