forumfresser
forumfresser

Reputation: 471

SWT Combo Listener getText() not updated

Hello fellow SWT programmers,

today I wanted to add a Listener to my custom SWT Combo view. (a bit modified) code:

combo.addListener(SWT.ALL, new Listener() {

  @Override
  public void handleEvent(Event event) {
       //some irrelevant code
       String text = combo.getText();
       System.out.println(text);
}

However, as I enter something into the text field, the text that was in the Combo View BEFORE I triggered the event is outputted, meaning that the combo.getText() returns the text it contained before the event was triggered.

How do I solve this issue and get the updated Combo text input within this Listener? I can't use a ModifyListener, it has to be the Listener interface (since I need to differ between the event types and do stuff accordingly).

Thanks in advance,

forumfresser

Upvotes: 0

Views: 759

Answers (1)

greg-449
greg-449

Reputation: 111142

SWT.ALL is not a valid value for addListener. As it happens it will be interpreted as SWT.KeyDown.

Use SWT.Modify to listen for modify events:

combo.addListener(SWT.Modify, new Listener() {

Upvotes: 2

Related Questions