URL Label : 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 




URL Label
    
//The contents of this file are subject to the Mozilla Public License Version 1.1
//(the "License"); you may not use this file except in compliance with the 
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
//
//Software distributed under the License is distributed on an "AS IS" basis,
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
//for the specific language governing rights and
//limitations under the License.
//
//The Original Code is "The Columba Project"
//
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. 
//
//All Rights Reserved.

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.net.URL;

import javax.swing.JLabel;

public class URLLabel extends JLabel {

  boolean entered = false;

  boolean mousehover;

  public URLLabel(URL url) {
    this(url, url.toString());
  }

  public URLLabel(URL url, String str) {
    super(str);

    setForeground(Color.blue);
    mousehover = false;

  }

  public void mouseEntered(MouseEvent e) {
    setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    entered = true;

    if (mousehover) {
      repaint();
    }
  }

  public void mouseExited(MouseEvent e) {
    setCursor(Cursor.getDefaultCursor());
    entered = false;

    if (mousehover) {
      repaint();
    }
  }

  public void mousePressed(MouseEvent e) {
  }

  public void mouseReleased(MouseEvent e) {
  }

  public void paint(Graphics g) {
    super.paint(g);

    if (entered || !mousehover) {
      Rectangle r = g.getClipBounds();

      g.drawLine(0, r.height - this.getFontMetrics(this.getFont()).getDescent()this
          .getFontMetrics(this.getFont()).stringWidth(this.getText()), r.height
          this.getFontMetrics(this.getFont()).getDescent());
    }
  }
}

   
    
    
    
  














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.Hyperlink Label
9.Bevel TextBevel Text
10.A JLabel that can be underlined, implements Scrollable
11.Gradient Label
12.Hyperlink Label 2
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.