Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Tutorials Swt Create ToolTip Text in SWT

Related Tutorials


 
 

Share on Google+Share on Google+

Create ToolTip Text in SWT

Advertisement
The ToolTip is the element of graphical user interface used in the conjunction with a cursor pointer. In SWT, the method setToolTipText() of class TabItem sets the tooltip text.

Create ToolTip Text in SWT

     

In this section, you will learn how to create ToolTip.

The ToolTip is the element of graphical user interface used in the conjunction with a cursor pointer. In SWT, the method setToolTipText() of class TabItem sets the tooltip text. In the given example, we have create tabs using the class TabFolder and TabItem to show the toolTipText.

The method tabFolder.getSelection() returns the selected TabItem.

Here is the code of ToolTipExample.java

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

public class ToolTipExample {
  public void run() {
  Display display = new Display();
  Shell shell = new Shell(display);
  shell.setLayout(new FillLayout());
  shell.setText("Show ToolTips");
  shell.setSize(180,150);
  create(shell);
  shell.open();
  while (!shell.isDisposed()) {
  if (!display.readAndDispatch()) {
  display.sleep();
  }
  }
  display.dispose();
  }
  private void create(Shell shell) {
  final TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
  TabItem one = new TabItem(tabFolder, SWT.NONE);
  one.setText("Tab 1");
  one.setToolTipText("This is Tab 1.");
 
  TabItem two = new TabItem(tabFolder, SWT.NONE);
  two.setText("Tab 2");
  two.setToolTipText("This is Tab 2.");
 
  TabItem three = new TabItem(tabFolder, SWT.NONE);
  three.setText("Tab 3");
  three.setToolTipText("This is Tab 3.");
 
  TabItem four = new TabItem(tabFolder, SWT.NONE);
  four.setText("Tab 4");
  four.setToolTipText("This is Tab 4.");
  
  tabFolder.setSelection(2);
  tabFolder.addSelectionListener(new SelectionAdapter() {
  public void widgetSelected(org.eclipse.swt.events.
  SelectionEvent event){

  System.out.println(tabFolder.getSelection()[0].getText()
   + 
" selected");
  }
  });
  }
  public static void main(String[] args) {
  new ToolTipExample().run();
  }
}

Output will be displayed as:

Download Source Code

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 4, 2008

Related Tutorials

Discuss: Create ToolTip Text in SWT  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com