LawRose February 2016

Java Eclipse input validation

So here it is: I'm writing a (swt)program.In my form, I have two text fields and a button, but when pressing the button I would like it to validate the (string)text fields. Asking the user for input if nothing in textfields?

Hopefully this question makes sense Thank you all in Advance!!

Answers


Pedro H February 2016

You must do this manually, adding a listern to button. If you your TextField is called textField and yout Button button, it will be something like:

\\previous code
button.addListener(SWT.Selection, new Listener() {
  public void handleEvent(Event e) {
    switch (e.type) {
    case SWT.Selection:
      if(textField.getText() == null || textField.getText().isEmpty()) ; //here you validate
      break;
    }
  }
});

Post Status

Asked in February 2016
Viewed 3,636 times
Voted 8
Answered 1 times

Search




Leave an answer