Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.

To get selected HTML on the loaded web page use the Browser.getSelectedHTML() method as described in the example below:


import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

 * The example demonstrates how to get selected HTML
 * on the loaded web page.
public class GetSelectedHTMLSample {
    public static void main(String[] args) {
        final Browser browser = new Browser();
        final BrowserView view = new BrowserView(browser);

        JButton button = new JButton("Get Selected HTML");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String html = browser.getSelectedHTML();
                        html, "Selected HTML", JOptionPane.PLAIN_MESSAGE);

        JFrame frame = new JFrame();
        frame.add(button, BorderLayout.NORTH);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);