简体   繁体   English

SWT文本小部件充当命令提示符

[英]SWT Text widget behave as Command promt

I am trying to create a applicatin with SWT Text widget. 我正在尝试使用SWT Text小部件创建一个applicatin。 The Text widget should act as command prompt asking input but not allowed to be delete after pressed enter. 文本小部件应充当命令提示符询问输入内容,但在按Enter键后不允许删除。 but characters can be deleted on same line before enter. 但可以在输入之前在同一行上删除字符。 Is this possible? 这可能吗? Thanks, Tor 谢谢,托

One approach is to set up a two widget layout. 一种方法是设置两个小部件布局。 Create one component for holding the terminal screen (non-editable) and a Text widget that holds your input and is editable. 创建一个用于保存终端屏幕的组件(不可编辑),并创建一个Text小部件以保存您的输入并且是可编辑的。 Following API should give you an idea on how to implement this behavior: 以下API应该使您了解如何实现此行为:

  • Every Text widget has a setEditable(boolean) method to set wether it can be edited or not. 每个Text小部件都有一个setEditable(boolean)方法来设置它是否可以编辑。

  • You can pass constants from class SWT to the constructor. 您可以将常量从类SWT传递给构造函数。 Ex.: 例如:

     new Text(shell, SWT.SINGLE) // creates single line text field new Text(shell, SWT.MULTI) // crates a multi line text field 
  • Maybe adding a KeyListener will help you. 也许添加KeyListener会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM