Hyperlink Label 2 : Label « Swing Components « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Swing Components » Label 




Hyperlink Label 2
    
/**
 * @(#)HyperlinkLabel.java
 */

//package aurora.util;

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


/**
 * Implementation of 
 @author Alex Kurzhanskiy
 @version $Id: HyperlinkLabel.java 38 2010-02-08 22:59:00Z akurzhan $
 */
public class HyperlinkLabel extends JLabel implements MouseListener {
  private static final long serialVersionUID = 5167616594614061634L;
  
  private URL url = null;
  
  
  public HyperlinkLabel(String label){
    super(label);
    addMouseListener(this);
  }
  public HyperlinkLabel(String label, URL url){
    this(label);
    this.url = url;
    setText("<html><a href=\"\">" + label + "</a></html>");
    setToolTipText("Go to: " + url.getRef());
  }
  public HyperlinkLabel(String label, String tip, URL url){
    this(label, url);
    setToolTipText(tip);
  }
  
  
  public void setURL(URL url){ this.url = url; }
  
  public URL getURL(){ return url; }

  public void mouseClicked(MouseEvent e) {
    HyperlinkLabel self = (HyperlinkLabele.getSource();
    if(self.url == null)
      return;
    if (Desktop.isDesktopSupported()) {
      Desktop desktop = Desktop.getDesktop();
      if (desktop.isSupported(Desktop.Action.BROWSE))
        try{
          desktop.browse(url.toURI());
          return;
        }
      catch(Exception exp){ }
    }
    JOptionPane.showMessageDialog(this, "Cannot launch browser...\n Please, visit\n" + url.getRef() "", JOptionPane.INFORMATION_MESSAGE);
    return;
  }

  public void mouseEntered(MouseEvent e) {
    e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    return;
  }

  public void mouseExited(MouseEvent e) {
    // TODO Auto-generated method stub
    return;
  }

  public void mousePressed(MouseEvent e) {
    // TODO Auto-generated method stub
    return;
  }

  public void mouseReleased(MouseEvent e) {
    // TODO Auto-generated method stub
    return;
  }
  
}

   
    
    
    
  














Related examples in the same category
1.MultiLine Label
2.Multi Line Label extends JComponent
3.Multi Line Label extends JPanel
4.Link Label
5.Vertical Label UI
6.Label with large font and ANTIALIAS paint
7.Label 3D
8.URL Label
9.Hyperlink Label
10.Bevel TextBevel Text
11.A JLabel that can be underlined, implements Scrollable
12.Gradient Label
13.Computes a reasonable set of labels for a data interval and number of labels.
14.Multi-label Label
15.Shadow Label
16.Button Label
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.