Home Tutorials Swt Create ToolTip Text in SWT



Create ToolTip Text in SWT
Posted on: October 4, 2008 at 12:00 AM
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

     

Related Tags for Create ToolTip Text in SWT:
cclasstextinterfaceioswtmethodusersedtabspointergraphipsetscursortooltipusingfolderintthistoolsetelementoocreatetabshowtexpoiexampleuncbitwithtopointlearnicalexamldshearextbieilititemsectionuseceincalasmnttabitemcajaceclemabimehowgraphicalxaxampstipsofoldatoldishallivmplgraphiceaandarxtwtttssthshoswavbfabapfaceicaicapleplndonolo


More Tutorials from this section

Ask Questions?    Discuss: Create ToolTip Text 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.