Answers for "how to add http link in joptionpane swing"

0

how to add http link in joptionpane swing

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class OptionPaneExample extends MouseAdapter{
    public static void main(String[] args) {
        String msg = "<html><u>http://java.sun.com</u></html>";
        JLabel url = new JLabel(msg);
        url.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        url.addMouseListener(new OptionPaneExample());

        JPanel message = new JPanel();
        message.add(new JLabel("Visit us at "));
        message.add(url);

        JOptionPane.showMessageDialog(null, message);
    }

    public void mousePressed(MouseEvent evt) {
        System.out.println("etc...");
    }

    public void mouseEntered(MouseEvent evt) {
        evt.getComponent().setForeground(new Color(0xC0, 0xC0, 0xF0));

    }

    public void mouseExited(MouseEvent evt) {
        evt.getComponent().setForeground(Color.BLACK);
    }
}
Posted by: Guest on August-03-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language