I'm trying to find out how to create a JTable
cell which contains Image, which should be clickable like an hyperlink. I'm able to load Image using default image renderer.
Can somebody explain me how to add hyperlink (mouse listener) for the each image (cell) in the last column of my table? so that, when the image link in jTable cell is clicked, I want it to open a pop-up with some message showing the error message.
Thanks, Chandra
To launch link in machine's default browser:
URI uri = null;
try {
uri = new URI(urlToOpen);
} catch (URISyntaxException e1) {
System.out.println("Malformed URI: " + uri);
}
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(uri);
} catch (IOException e2) {
// If the user default browser is not found, or it fails
// to be launched, or the default handler application
// failed to be launched
JOptionPane.showMessageDialog(null,
"The application could not find any compatible browser.");
}
You can do this on click of Image.
Edit based on comments:
Add listener to image and then you can open a JOptionPane
or JDialog
on click of Image.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.