title: How to do validation of input of a SWT widget (Text)
body: <p>How can add validation to an <code>SWT</code> widget? E.g. <code>Text</code>?<br>
  I tried both of the following (found online):  </p>
  
  <pre><code>txtPort.addListener(SWT.Verify,new Listener() {  
    @Override  
    public void handleEvent(Event event) {  
        String port = ((Text)event.widget).getText();  
        try{  
            int portNum = Integer.valueOf(port);  
            if(portNum &lt;0 || portNum &gt; 65535){  
                  event.doit = false;  
           }  
        }  
        catch(Exception ex){  
           event.doit = false;  
        }                 
     }  
  });  
  </code></pre>
  
  <p>Also:  </p>
  
  <pre><code>txtPort.addVerifyListener(new VerifyListener() {  
     @Override  
     public void verifyText(VerifyEvent e) {  
       String port = ((Text)e.widget).getText();  
        try{  
           int portNum = Integer.valueOf(port);  
           if(portNum &lt;0 || portNum &gt; 65535){  
               e.doit = false;  
            }  
        }  
        catch(Exception ex){  
            e.doit = false;  
        }  
     }  
  });     
  </code></pre>
  
  <p>If I add a character, the cursor stucks and I can not even delete it.<br>
  Even if I just delete everything the first time, the cursor also stucks and I can not write anything else.<br>
  What am I messing up here? How am I supposed to do the validation of a <code>Text</code>?<br>
  In this case I only want to accept a number serving as port.</p>