Go: JAVA_SWT Common events, and methods

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/lyq19870515/article/details/9450275

Get Focus Event: Text.addlistener (SWT. Focusin,NewListener () { Public voidhandleevent (Event e) {//handle the event that gets focus   }    }); Loss of focus Event: Text.addlistener (SWT. Focusout,NewListener () { Public voidhandleevent (Event e) {//dealing with events that lose focus    }    }); Mouse Move-out event: Treecom.gettree (). Addmousetracklistener (NewMousetracklistener () {@Override Public voidMouseHover (MouseEvent e) {} @Override Public voidMouseexit (MouseEvent e) {//Move in Events} @Override Public voidMouseEnter (MouseEvent e) {//Move Out Event        }  }); button click event: Button.addselectionlistener (NewSelectionadapter () {@Override Public voidwidgetselected (selectionevent e) {//Event Handling       }  }); Left mouse button Double-click event: Tree.addlistener (SWT. MouseDoubleClick,NewListener () {@Override Public voidHandleevent (Event event) {if(Event.button! = 1) {//The key is not left-click to jump. 1 left, 2 middle, 3 right            return; }          //Event Handling    }  }); Table Set Row Height event: Table_1.addlistener (SWT. MeasureItem,NewListener () {@Override Public voidHandleevent (Event event) {//Handling EventsEvent.height = 30; //Remove the current event. Otherwise, you can click on the table to perform many events.Table.removelistener (SWT. MeasureItem, This);   }  }); button click event: Button.addselectionlistener (NewSelectionadapter () {@Override Public voidwidgetselected (selectionevent e) {//Events}); Double-click the tree. Gets the name of the current click node: Tree.addlistener (SWT. MouseDoubleClick,NewListener () {@Override Public voidHandleevent (Event event) {if(Event.button! = 1) {//The right mouse button is not clicked.             return; } Point Point=NewPoint (Event.x, EVENT.Y);//gets the coordinate point of the current click. TreeItem item = Tree.getitem (point);//gets the node from the coordinate point. //gets all the selected tree nodes. //TreeItem [] ItemArray = Global.gettree_userorgan (). Gettree (). GetSelection (); System.out.println (Tree.gettext ());  }  }); Gets the size of the Eclipse interface (size):P oint size=platformui.getworkbench (). Getactiveworkbenchwindow (). Getshell (). GetSize (); Gets the current position of the mouse: Point points=display.getcurrent (). Getcursorlocation (); Get screen resolution: monitor[] Monitors=Shell.getdisplay (). Getmonitors ();  for(inti = 0; i < monitors.length; i++) {Monitor m=Monitors[i];  System.out.println (M.getbounds (). toString ()); }  //Program output: Rectangle {0, 0, 1366, 768}the check box for the tree selects the event: Tree.addlistener (SWT. Selection,NewListener () {@Override Public voidHandleevent (Event event) {if(Event.detail = =SWT. CHECK) {TreeItem Item=(TreeItem) Event.item; if(Item = =NULL) {              return; }          BooleanChecked =item.getchecked (); if(checked) {//If a new element is selected. The other selected elements are canceled.              for(inti = 0; I < Projectmoudeltree.gettreeitemlist (). Size (); i++) {TreeItem Tempitem=projectmoudeltree.gettreeitemlist (). get (i); if(Item! =Tempitem) {tempitem.setchecked (false);  }              }          }      }  }  }); check box to select the event://Create a check box. The check box cannot have a read-only property (SWT.  READ_ONLY), or you'll think you're a button. CheckBox =NewButton (composite, SWT.  CHECK); Checkbox.settext ("Test check box"); Checkbox.addselectionlistener (NewSelectionlistener () {@Override Public voidwidgetselected (selectionevent e) {//check box to trigger this event when Cancel is selected. //checkbox.setselection (false); The Set check box is selected. //If you want the check box to be a read-only property        if(Checkbox.getselection ()) {checkbox.setselection (false); } Else{checkbox.setselection (true); }} @Override Public voidwidgetdefaultselected (Selectionevent e) {}}); SWT with vertical scroll bar text automatically scroll to the bottom of the end (such as display chat information, log display, etc.) has always been thought to be the setting of the scroll bar. The result is nothing like that. Text Tbx_text=NewText (Group, SWT. BORDER |SWT. WRAP| Swt. V_scroll |SWT.      READ_ONLY);  Tbx_text.settopindex (Integer.max_value); Directly set its display line number on the line, set the maximum, will show to the bottom. Dialog modelling:Private voidCreatecontents () {<span style= "White-space:pre" > </span>Shell=NewShell (GetParent (), GetStyle () | Swt. shell_trim| Swt. Application_modal);

Go: JAVA_SWT Common events, and methods

Related Article

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.