Eclipse plugin: how to make Combo to handle Enter key pressing? That is after entering some text user can press Enter, that will case some processing. The same processing can be started by Button "Run" click.
Asked
Active
Viewed 1,973 times
1
-
There is .addModifyListener method for the combo http://stackoverflow.com/questions/11653247/can-i-detect-change-in-text-fields-in-swt But I can't see that I can detect Enter was pressed. – Paul Verest Jul 07 '13 at 11:09
1 Answers
2
Just add a Listener
for SWT.KeyUp
and check if the entered character is equal to SWT.CR
.
Here is some code:
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();
}
Looks like this:
And will show this dialog when the user presses enter:

Baz
- 36,440
- 11
- 68
- 94