Label Highlighting : Label « SWT JFace Eclipse « Java






Label Highlighting

Label Highlighting

/******************************************************************************
 * Copyright (c) 1998, 2004 Jackwind Li Guojie
 * All right reserved. 
 * 
 * Created on Oct 28, 2003 8:10:30 PM by JACK
 * $Id: LabelHighlighting.java,v 1.1 2003/12/22 12:07:54 jackwind Exp $
 * 
 * visit: http://www.asprise.com/swt
 *****************************************************************************/

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class LabelHighlighting {
  Display display = new Display();
  Shell shell = new Shell(display);
  Label label = new Label(shell, SWT.SHADOW_IN | SWT.CENTER);
  Listener listener = new MouseEnterExitListener();
  
  public LabelHighlighting() {
    
    label.setText("Point your cursor here ...");
    label.setBounds(30, 30, 200, 30);
    
    label.addListener(SWT.MouseEnter, listener);
    label.addListener(SWT.MouseExit, listener);
    
    shell.setText("Move your cursor to test ...");
    shell.setSize(260, 120);
    shell.open();    
    
      
    while(! shell.isDisposed()) {
      if(! display.readAndDispatch()) {// If no more entries in event queue
        display.sleep();
      }
    }
    
    display.dispose();
  }
  
  class MouseEnterExitListener implements Listener {
    public void handleEvent(Event e) {
      switch (e.type) {
        case SWT.MouseEnter :
          display.syncExec(new Runnable() {
            public void run() {
              label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
              label.setText("Cursor enters the label");
            }
          });
          
          break;

        case SWT.MouseExit :
          display.syncExec(new Runnable() {
            public void run() {
              label.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
              label.setText("Cursor leaves the label");
            }
          });
          
          break;
      }
    }
  }


  public static void main(String[] args) {
    new LabelHighlighting();
  }
}


           
       








Related examples in the same category

1.First SWT: LabelFirst SWT: Label
2.SWT Label With TextSWT Label With Text
3.Label Highlighting 3Label Highlighting 3
4.Label Highlighting 2Label Highlighting 2
5.CLabel BorderCLabel Border
6.CLabel Gradient Background CLabel Gradient Background
7.Label SeparatorLabel Separator
8.Label WrapLabel Wrap
9.Text and Label demoText and Label demo
10.Formatted TextFormatted Text
11.Demonstrates LabelsDemonstrates Labels
12.Demonstrates CLabel gradientsDemonstrates CLabel gradients
13.Demonstrates CLabel 2Demonstrates CLabel 2
14.Demonstrates CLabelDemonstrates CLabel
15.Create a label (a separator)Create a label (a separator)
16.Create a label (with an image)Create a label (with an image)
17.how to resize the Label when the Shell resizes using a Listener mechanismhow to resize the Label when the Shell resizes using a Listener mechanism
18.How to resize the Label when the Shell resizes using a LayoutHow to resize the Label when the Shell resizes using a Layout