```
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 sample demonstrates how to get selected text on a web page.
*/
public class GetSelectedTextSample {
public static void main(String[] args) {
final Browser browser = new Browser();
final BrowserView browserView = new BrowserView(browser);
JButton button = new JButton("Get Selected Text");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedText = browser.getSelectedText();
JOptionPane.showMessageDialog(browserView,
selectedText, "Selected Text", JOptionPane.PLAIN_MESSAGE);
}
});
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(button, BorderLayout.NORTH);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.loadURL("http://teamdev.com");
}
}
```