Home Ask Login Register

Developers Planet

Your answer is one click away!

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!!


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

Post Status

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


Leave an answer

Quote of the day: live life