Common event listeners of SWT [mouselistener]

Source: Internet
Author: User

1. There are three methods for mouse mouselistener:

Mousedown: triggered by a click;

Mouseup: release;

Mousedoubleclick: Double-click;

Right-click on the left

2. attributes:

Button: INT: Left = 1; center = 2; Right = 3;

Statemask: Same as keylistener;

X, Y: coordinates at the bottom

Package COM. iteye. niewj. SWT. chapter1; import Org. eclipse. SWT. SWT; import Org. eclipse. SWT. events. mouseevent; import Org. eclipse. SWT. events. mouselistener; import Org. eclipse. SWT. layout. rowdata; import Org. eclipse. SWT. layout. rowlayout; import Org. eclipse. SWT. widgets. button; import Org. eclipse. SWT. widgets. display; import Org. eclipse. SWT. widgets. shell; import Org. eclipse. SWT. widgets. text; public class mouseevents How {/*** @ author niewj * @ since 2012-6-4 */public static void main (string [] ARGs) {// external shelldisplay display = display. getdefault (); final shell = new shell (Display); shell. setbounds (1, 20,100,450,500); shell. settext ("mouse event"); // layout manager rowlayout layout = new rowlayout (); layout. spacing = 30; layout. marginwidth = 30; layout. marginheight = 40; layout. wrap = true; layout. type = SWT. vertical; shell. setlayout (layout );/ /Rowdata controls the widget size and hide/* textrowdata textdata = new rowdata (); // true hides the widget. The occupied space is ignored, and textdata is moved from the bottom (back) to the Front (back. exclude = false; textdata. height = 150; textdata. width = 300; // * buttonrowdata btndata = new rowdata (); btndata. exclude = false; btndata. height = 30; btndata. width = 200; // 1. buttonfinal button = new button (shell, SWT. none); button. settext ("button above"); button. setlayoutdata (btndata); // 2. final text = new text (Shell, SWT. none); text. settext ("text box"); text. setlayoutdata (textdata); // 3. buttonfinal button button2 = new button (shell, SWT. none); button2.settext ("button below"); button2.setlayoutdata (btndata); text. addmouselistener (New mouselistener () {@ overridepublic void mouseup (mouseevent e) {string MSG = ""; Switch (E. button) {Case 1: MSG = ""; break; Case 2: MSG = ""; break; Case 3: MSG = ""; break;} text. settext ("Release text box; event Source :" + MSG) ;}@ overridepublic void mousedown (mouseevent e) {string MSG = ""; Switch (E. button) {Case 1: MSG = ""; break; Case 2: MSG = ""; break; Case 3: MSG = ""; break;} text. settext ("click the text box, source:" + MSG) ;}@ overridepublic void mousedoubleclick (mouseevent e) {string MSG = ""; Switch (E. button) {Case 1: MSG = ""; break; Case 2: MSG = ""; break; Case 3: MSG = ""; break;} text. settext ("double-click Text Box, event Source:" + MSG) ;}}); // display shell. O Pen (); While (! Shell. isdisposed () {If (! Display. readanddispatch () {display. Sleep () ;}} display. Dispose ();}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.