在以swt格式提交的多行文本上使用Tab键? [英] Use Tab-key on a multiline text filed in swt?

查看:97
本文介绍了在以swt格式提交的多行文本上使用Tab键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止多行文本字段窃取" Tab键?

How do I prevent a multi-line text field from "stealing" tab-key presses?

我的意思是:我想使用TAB在窗口的各个元素之间循环,但是当我输入多行文本时,TAB成为普通"键,只需在我输入的文本中插入制表符即可.

I mean: I'd like to use TAB to cycle between the elements of a window, but when I enter the multiline text, TAB becomes a "normal" key, and simply inserts tabulators into the text I'm typing.

我该如何处理?我应该编写一些自定义侦听器,还是可以使用SWT常量更改组件的行为?

How do I handle this? Should I write some custom listener, or can I change the behaviour of the component by using an SWT constant?

推荐答案

SWT定义了一种使用TraverseListener类实现此类行为的机制.以下代码段(摘自

SWT defines a mechanism for implementing this kind of behaviour using the TraverseListener class. The following snippet (taken from here) shows how:

Text text1 = new Text(shell, SWT.MULTI | SWT.WRAP);
text1.setBounds(10,10,150,50);
text1.setText("Tab will traverse out from here.");
text1.addTraverseListener(new TraverseListener() {
    public void keyTraversed(TraverseEvent e) {
        if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
            e.doit = true;
        }
    }
});

这篇关于在以swt格式提交的多行文本上使用Tab键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆