Search in sources :

Example 41 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class MuteAudio 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 muteAudioButton = new JButton("Mute Audio");
        muteAudioButton.addActionListener(e -> {
            Audio audio = browser.audio();
            if (audio.isMuted()) {
                audio.unmute();
            } else {
                audio.mute();
            }
            updateButtonText(muteAudioButton, browser);
        });
        JFrame frame = new JFrame("Mute Audio");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(muteAudioButton, BorderLayout.NORTH);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().loadUrl("https://www.youtube.com/");
}
Also used : JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Audio(com.teamdev.jxbrowser.media.Audio) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 42 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class PrintFromJava 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 print = new JButton("Print");
        print.addActionListener(e -> browser.mainFrame().ifPresent(Frame::print));
        JFrame frame = new JFrame("Print From Java");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.add(print, BorderLayout.NORTH);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        browser.navigation().loadUrl("https://www.google.com");
    });
}
Also used : JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 43 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class PrintFromJavaScript 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("Print From JavaScript");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        browser.mainFrame().ifPresent(mainFrame -> {
            mainFrame.loadHtml("<html><body><a href='#' onclick='window.print();'>" + "Print</a></body></html>");
        });
    });
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 44 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class SaveWebPage 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("Save Web Page");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().loadUrlAndWait("https://www.google.com");
    Path file = Paths.get("index.html");
    Path dir = Paths.get("resources_dir");
    if (browser.saveWebPage(file, dir, SavePageType.COMPLETE_HTML)) {
        System.out.println("The web page has been saved to " + file.toAbsolutePath() + "\n" + "The resources has been saved to " + dir.toAbsolutePath() + " directory");
    } else {
        System.err.println("Failed to save the web page to " + file);
    }
}
Also used : Path(java.nio.file.Path) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 45 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class JarProtocol method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).addScheme(Scheme.JAR, new InterceptJarRequestCallback()).build());
    Browser browser = engine.newBrowser();
    invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("JAR Protocol Handler");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    // Load the index.html file located inside a JAR archive added to this Java app classpath.
    URL resource = JarProtocol.class.getResource("/resources/index.html");
    if (resource != null) {
        browser.navigation().loadUrl(resource.toString());
    }
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) URL(java.net.URL) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)49 Browser (com.teamdev.jxbrowser.browser.Browser)47 JFrame (javax.swing.JFrame)47 Engine (com.teamdev.jxbrowser.engine.Engine)46 BorderLayout (java.awt.BorderLayout)8 HARDWARE_ACCELERATED (com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED)7 SwingUtilities (javax.swing.SwingUtilities)7 WindowConstants (javax.swing.WindowConstants)7 EngineOptions (com.teamdev.jxbrowser.engine.EngineOptions)5 Document (com.teamdev.jxbrowser.dom.Document)4 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)4 WindowAdapter (java.awt.event.WindowAdapter)4 WindowEvent (java.awt.event.WindowEvent)4 Navigation (com.teamdev.jxbrowser.navigation.Navigation)3 JButton (javax.swing.JButton)3 Frame (com.teamdev.jxbrowser.frame.Frame)2 Path (java.nio.file.Path)2 Content (com.intellij.ui.content.Content)1 UnsupportedRenderingModeException (com.teamdev.jxbrowser.browser.UnsupportedRenderingModeException)1 SpellCheckCompleted (com.teamdev.jxbrowser.browser.event.SpellCheckCompleted)1