Source Code : Label Highlighting

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

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();
  }
}


           
       

Thank with us