Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(text.length() > wrapLength)
- {
- //break the text into substrings and insert a <br /> at wrapLength
- //the difficulty is in figuring out the value of wrapLength
- }
- import java.awt.Color;
- import java.awt.Desktop;
- import java.awt.Font;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.io.IOException;
- import java.net.URI;
- import java.net.URISyntaxException;
- import javax.swing.JLabel;
- public class Hyperlink extends JLabel
- {
- private URI uri;
- private String baseText;
- public Hyperlink(String text, String uri, Font font, Color textColor)
- {
- super(text);
- baseText = text;
- setFont(font);
- setForeground(textColor);
- setOpaque(false);
- if(Desktop.isDesktopSupported())
- {
- try
- {
- setToolTipText(uri);
- this.uri = new URI(uri);
- addMouseListener(new LinkMouseListener());
- }
- catch(URISyntaxException ex)
- {
- }
- }
- }
- private class LinkMouseListener extends MouseAdapter
- {
- @Override
- public void mouseClicked(MouseEvent e)
- {
- Desktop desktop = Desktop.getDesktop();
- try
- {
- desktop.browse(uri);
- }
- catch(IOException ioe)
- {
- System.out.println("Something went wrong..."); //DELETE
- }
- }
- @Override
- public void mouseEntered(MouseEvent e)
- {
- setText("<html><u>" + baseText + "</u></html>");
- }
- @Override
- public void mouseExited(MouseEvent e)
- {
- setText(baseText);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement