Problem in SWT Focuslistener can be used to monitor whether a TextField is selected,
In the following program, I add Focuslistener to two text, which is the function of
When text is selected, the above text will be selected as a full state.
I don't know why it works only for the first one.
It was later discovered that the two-text type was different.
Just the text of Swt.single, as if SelectAll () is invalid.
Display D;
Shell s;
TextField1 () {
D = new Display ();
s = new Shell (d);
S.setsize (250,250);
S.settext ("A Text Field Example");
Text Text1 = new text (s, SWT. WRAP | Swt. BORDER);
Text1.setbounds (100,50,100,20);
Text1.settextlimit (5);
Text1.settext ("12345");
Text Text2 = new text (s, SWT. Single | Swt. BORDER);
Text2.setbounds (100,75,100,20);
Text2.settextlimit (10);
Add a Focus listener
Focuslistener Focuslistener = new Focuslistener () {
public void focusgained (FocusEvent e) {
Text T = (text) e.widget;
T.selectall ();
}
public void Focuslost (FocusEvent e) {
Text T = (text) e.widget;
if (T.getselectioncount () > 0) {
T.clearselection ();
}
}
};
Text1.addfocuslistener (Focuslistener);
Text2.addfocuslistener (Focuslistener);
S.open ();
while (!s.isdisposed ()) {
if (!d.readanddispatch ())
D.sleep ();
}
D.dispose ();
}
public static void Main (string[] args) {
TextField1 tx = new TextField1 ();
}
}
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.