Differences
This shows you the differences between two versions of the page.
— |
override_default_action_for_swt_text_field [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Override Default Action for SWT Text Field ====== | ||
+ | Normally the default button will be triggered when the enter key is pressed in a text field and the text field will loose the focus. | ||
+ | This can be change/ | ||
+ | |||
+ | <sxh java> | ||
+ | Text text = new Text(shell, SWT.SINGLE | SWT.BORDER); | ||
+ | text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | ||
+ | text.setText(" | ||
+ | text.addSelectionListener(new SelectionAdapter() { | ||
+ | public void widgetDefaultSelected(SelectionEvent e) { | ||
+ | System.out | ||
+ | .println(" | ||
+ | } | ||
+ | }); | ||
+ | text.addTraverseListener(new TraverseListener() { | ||
+ | public void keyTraversed(TraverseEvent e) { | ||
+ | if (e.detail == SWT.TRAVERSE_RETURN) { | ||
+ | e.doit = false; | ||
+ | e.detail = SWT.TRAVERSE_NONE; | ||
+ | } | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | {{tag> |