How to listen to text modify event of group widget (Java SWT)? -
What do I do: when I change the title of the group widget (by calling The problem now is how to change the text of the group widget change the text? I tried I have workaround here Any time the title change triggers the Paint Event I have placed the group widget title text as data and compare the change in the paint listener. Note that the paint listener will be asked many times, so it is suggested that you put a lot of code inside it. setText ()) method), I need to check the headline, if there are some characters, then I will do something.
addListener (SWT.Modify, listener); Method, (see examples given below), it does not work.
import org.eclipse. Swt.SWT; Import org.eclipse.swt.events.SelectionAdapter; Import org.eclipse.swt.events.SelectionEvent; Import org.eclipse.swt.layout.GridLayout; Import org.eclipse.swt.widgets.Button; Import org.eclipse.swt.widgets.Display; Import org.eclipse.swt.widgets.Event; Import org.eclipse.swt.widgets.Group; Import org.eclipse.swt.widgets.Listener; Import org.eclipse.swt.widgets.Shell; Public class test {public static zero main (string [] args) {final display display = new display (); Shell shell = new shell (display); Shell.setLayout (new grid layout (1, wrong)); shell.setText ("Stackoverflow"); Last Group Group = New Group (Shell, SWT.NONE); Group.setText ("title0"); Group.addListener {SWT.Modify, new listener} {@Override public void handleEvent} {// TODO auto generated method stub System.out.println ("the group's title has changed");}}); Button BTN = new button (shell, SWT.NONE); Btn.setText ("Press to set the group's title."); Btn.addSelectionListener (New selectionAdapter () {@ Override Public Wide Widgets Selected (SelectionEvent e) {// TODO Auto generated method stub group .set text ("title1");}}); shell.pack (); Shell.open (); While (! Shell.isDisposed ()) {if (! Display.readAndDispatch ()) {display.sleep (); }} Display.dispose (); }}
setData ()
group.setData (new string) >>
PaintListener (Group.getText ())); Group.addPaintListener (New Penaltyist) {@ Override Public Wide Paint Control (Paint Event E) {If (Group's E. Videst Instances) {Group Group = (Group) EWDT; String Data = (string) grp.getData (); (Data.equals (grp.getText ())) {System.out.println ("Title changed"); grp.setData (grp.getText ()); // new as data Keep changed title}}}});
Comments
Post a Comment