iwebie
HOME MOVIES TV SHOWS SPORTS GENERAL
 RSSPRIVACY
 

How to create a JLabel with HyperLink in Java
Posted by admin on October 14th, 2008

Watch over 100,000 movies and TV shows on your PC

Java Program: This program creates a JLabel with a HyperLink. If you click on this link, a browser will open with the adress embeded.

[sourcecode language='java']

package javaapplicationmodels;
 
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
 
public class JLabelLink extends JFrame {

private static final long serialVersionUID = 1L;

public JLabelLink() {
  super() ;
  setTitle( “Click on the JLabel to start the webpage.” ) ;
  setDefaultCloseOperation( EXIT_ON_CLOSE ) ;
              
     JPanel pane = new JPanel();
     setContentPane(pane);
     setLayout(new FlowLayout());
                              
     JLabel label= new JLabel( “Visit iWebie” ,  JLabel.CENTER );
     label.setBackground(Color.RED);
     getContentPane().add(label) ;
              
     label.addMouseListener(new java.awt.event.MouseAdapter() {
           public void mouseClicked(java.awt.event.MouseEvent evt) {
              if(evt.getClickCount() > 0){
                try {
                        Process pc = Runtime.getRuntime().exec(”cmd.exe /c start http://www.iwebie.com”);
                    } catch (IOException ex) {
                        System.out.println(ex.getMessage());
                        System.out.println();
                    }
               }
            }
            });
            setSize( 400 , 100 );              
            setVisible( true );              
  }
 
 public static void main(String[] args) {
  new JLabelLink () ;
 }
}

[/sourcecode]

Bookmark Article
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Propeller
6 Responses to “How to create a JLabel with HyperLink in Java”
  1. Henrry Iguaro Says: December 3rd, 2008 at 2:34 am

    It does not work in Linux!

  2. Kamil Páral Says: March 3rd, 2009 at 12:02 am

    This is really lame.

  3. neha Says: March 5th, 2009 at 11:21 am

    very good example…thanxxxxxxxxx

  4. Seshaya Says: March 16th, 2009 at 8:40 am

    This may not be revelant but i figured i’d post this anyway. If you’re using ubuntu 8.10 you may be in for some issues with the network manager. For some unknown reason it stops functioning. You will need to manually set you’re resolv.conf with your ISP’s DNS servers. That file is located in /etc/network/resolv.conf

  5. satyam Says: March 25th, 2009 at 12:15 pm

    thank u 4 ur code………its a good example for creating hyper links…….its help ful 2 my project…..

  6. Mush Says: December 4th, 2009 at 2:22 pm

    It does not only “not work in Linux”. In fact, it works on Windows exclusively.
    Please do not spread this bad code. Replace it with a proper solution or remove it or – at the very least- inform people that this is nothing but a workaround for confirmed windows-only environments.

Leave a Reply

Most Popular

Watch over 100,000 movies and TV shows on your PC
Recent Posts

  • Watch Crazy on the Outside Online Free
  • Watch It’s Complicated Full Video Online
  • Watch Leap Year Free Stream Online
  • Watch Manchester United vs Birmingham Live Stream
  • Watch Avatar Online Stream
  • Watch Nine Online Video
  • Watch Crazy Heart Full Stream
  • Modern Family Season 1 Episode 11 | Watch Modern Family s01e11 Up All Night Full Episode
  • Burnley vs Arsenal EPL | Watch Burnley vs Arsenal Live Stream
  • Watch The Princess and the Frog Online Free

Warning: include(adbottom.html) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/iwebie.com/httpdocs/wp-content/themes/iWebie/rightsidebar.php on line 20

Warning: include() [function.include]: Failed opening 'adbottom.html' for inclusion (include_path='.:/opt/lsws/lsphp5/lib/php') in /var/www/vhosts/iwebie.com/httpdocs/wp-content/themes/iWebie/rightsidebar.php on line 20
Archives

  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
Powered by WordPress