gpt4 book ai didi

java - Eclipse插件: make Combo to handle Enter key

转载 作者:行者123 更新时间:2023-11-30 04:19:18 26 4
gpt4 key购买 nike

Eclipse插件:如何使Combo处理Enter键按下?也就是说,输入一些文本后,用户可以按 Enter 键,这将进行一些处理。单击“运行”按钮可以启动相同的处理。

org.eclipse.swt.widgets.Combo

最佳答案

只需为 SWT.KeyUp 添加一个 Listener 并检查输入的字符是否等于 SWT.CR

这是一些代码:

public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(1, true));

final Combo combo = new Combo(shell, SWT.NONE);

combo.addListener(SWT.KeyUp, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
if(arg0.character == SWT.CR)
MessageDialog.openInformation(shell, "Input", "You entered: " + combo.getText());
}
});

shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

看起来像这样:

enter image description here

当用户按下回车键时将显示此对话框:

enter image description here

关于java - Eclipse插件: make Combo to handle Enter key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17511442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com