How to create hyperlink in desktop application
Suppose, we need link (hyperlink) in our desktop swing application, and clicking it should open specified page in default browser.
Try this code:
Button clickmeLink = new Button("<html><u>Click Me!</u><html>");
clickmeLink.setBorder(null);
clickmeLink.setColor(Color.blue);
clickmeLink.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (Desktop.isDesktopSupported()) {
if (desktop == null) {
desktop = Desktop.getDesktop();
}
try {
desktop.browse(new java.net.URI("http://google.com"));
} catch (Exception ex) {
//TODO: code something
}
} else {
//tell your user that she needs Java6 or higher
}
}
});
Related posts:























