how to add http link in joptionpane swing

Solutions on MaxInterview for how to add http link in joptionpane swing by the best coders in the world

showing results for - "how to add http link in joptionpane swing"
Claudio
16 Jan 2019
1import java.awt.*;
2import java.awt.event.*;
3import javax.swing.*;
4
5public class OptionPaneExample extends MouseAdapter{
6    public static void main(String[] args) {
7        String msg = "<html><u>http://java.sun.com</u></html>";
8        JLabel url = new JLabel(msg);
9        url.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
10        url.addMouseListener(new OptionPaneExample());
11
12        JPanel message = new JPanel();
13        message.add(new JLabel("Visit us at "));
14        message.add(url);
15
16        JOptionPane.showMessageDialog(null, message);
17    }
18
19    public void mousePressed(MouseEvent evt) {
20        System.out.println("etc...");
21    }
22
23    public void mouseEntered(MouseEvent evt) {
24        evt.getComponent().setForeground(new Color(0xC0, 0xC0, 0xF0));
25
26    }
27
28    public void mouseExited(MouseEvent evt) {
29        evt.getComponent().setForeground(Color.BLACK);
30    }
31}