Home Tutorials Swt How to create Link in SWT



How to create Link in SWT
Posted on: October 3, 2008 at 12:00 AM
In this section, you will study how to create Link in a text.

How to create Link in SWT

     

In this section, you will study how to create Link in a text.

SWT allows to create link by using the class Link of package org.eclipse.swt.widgets. The class Link displays the specified text with links. The method setText(message) sets the text specified. 

Following code calls the Event class and print the selected link on the console:

ink.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
System.out.println("You have selected: "+event.text);
}
});

Here is the code of CreateLinkExample.java

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;

  public class CreateLinkExample{

  public static void main(String[] args) {
  Display display = new Display();
  Shell shell = new Shell(display);
  Link link = new Link(shell, SWT.NONE);
  String message = "Java is an <a>Platform Independent</a>, 
  <a>Robust</a>,<a>Object Oriented</a>Programming Language.
   Also have<a> Automatic Memory Management.</a>"
;
  link.setText(message);
  link.setSize(400100);
  link.addListener(SWT.Selection, new Listener() {
  public void handleEvent(Event event) {
  System.out.println("You have selected: "+event.text);
  }
  });
  shell.setText("Show Link");
  shell.open();
  shell.pack();
  while (!shell.isDisposed()) {
  if (!display.readAndDispatch())
  display.sleep();
  }
  display.dispose();
  }
}

Output will be displayed as:

On selecting Platform Independent, it will be printed on the console.

Download Source Code

     

Related Tags for How to create Link in SWT:
ceclipseclasstextioswtmethodgetlinkdisplayipwidgetssetswidgetusingclithismessageidpackagesetcreateiflinkstexiestudywithtociwsexteilitsectionlisplpeinasmplaypssageisppackclesspecallagemehowacksssaspdisplaysessclipatpackisinkllgetseasaxtwidwtttssthswstdispeclorgplono


More Tutorials from this section

Ask Questions?    Discuss: How to create Link in SWT  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.