Embedding a clickable HTML image in a JLabel

A JLabel is able to render HTML but it does not respond to clicks on anchor tags. You could do something simple like add a MouseListener to your JLabel and respond to mouse events like a normal browser would.


import java.awt.event.*;
import java.awt.font.*; 
import javax.swing.*;
import java.util.*;
import java.text.*;
import java.awt.*;
public class Main extends JFrame {
   public Main() {
      getContentPane().setLayout(new FlowLayout());
      final JLabel label = new JLabel("<html><a href="dummy"><img src="file:c:\esuslogo.gif"></a></html>");
      label.addMouseListener(new MouseAdapter() {
         public void mouseEntered(MouseEvent me) {
            label.setCursor(new Cursor(Cursor.HAND_CURSOR));
         public void mouseExited(MouseEvent me) {
         public void mouseClicked(MouseEvent me) {
            System.out.println("Clicked on JLabel image");
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent event) {
   public static void main(String[] args) {
      (new Main()).show();