2010-04-27 45 views
2
Label label1 = new Label(container, SWT.NULL); 
    label1.setText("Enter the Password "); 
    text1 = new Text(container, SWT.BORDER | SWT.PASSWORD); 
    text1.setText(""); 
    text1.addKeyListener(new KeyListener() { 


     public void keyPressed(KeyEvent e) { 
     } 

     public void keyReleased(KeyEvent e) { 
      if (!text5.getText().isEmpty()) { 
       setPageComplete(false); 

      } 
     } 

    }); 

嗨,我創建窗體使用SWT在日食任何人都可以告訴我如何驗證上面的表單條目是示例代碼的..實際上我想驗證密碼字段它應該是最小長度6.如何要做到這一點,請回復。如何驗證SWT表單?

回答

1

您可以使用消息管理器,如Eclipse Form文章中所述。

如上所述,支持已被添加到窗體標題中顯示消息。爲了更容易地處理表單中的多個消息,通過IManagedForm接口在3.3中提供了消息管理器。管理器作爲界面提供(IMessageManager)。

消息管理器將一次跟蹤用戶的多條消息,並將在任何給定時間(ERROR > WARNING > INFO)顯示基於文本的最嚴重消息。
它還提供了添加消息時將控件與其關聯的功能。如果這樣做,消息管理器將用適合於消息類型的圖像來修飾指定的控件。

alt text


關於這個具體問題,你可以看看這個問題類似的實現,如org.eclipse.team.internal.ccvs.ui.wizards.ConfigurationWizardMainPage class

// Password 
createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_password); 
passwordText = createPasswordField(g); 
passwordText.addListener(SWT.Modify, listener); 

Listener listener = new Listener() { 
    public void handleEvent(Event event) { 
    if (event.widget == passwordText) { 
     // check its length 
+0

能否請您給在上面的參考解決方案問題......即密碼字段驗證。 – Rahul 2010-04-28 04:32:28