47755

Java SWT User Input Validation

Question:

What is the Java convention when it comes to user input validation in SWT? I read that there are FieldEditors which are very convenient fields but sadly only for preferences and dialogue boxes.

I also read that there is an IValidator interface. But it is often used with data binding, which is in my case, most of my inputs do not need any data binding yet. Also, IValidator requires me to write my own validation methods even for simple validations such as integer only, letters only, etc.

Since the FieldEditors cannot be applied in normal usage of input fields, what other convenient way can I use to do validation on user inputs? I am using SWT for my Java GUI.

Thanks!

Answer1:

You can validate the input of your control in a VerifyListener. See <a href="http://www.eclipsezone.com/eclipse/forums/t60539.html" rel="nofollow">this forum thread</a> for further explanation.

Alternatively, you can check out <a href="http://marketplace.eclipse.org/content/rcp-toolbox-0" rel="nofollow">RCP Toolbox</a> which has a built-in easy-to-use validation framework. See <a href="http://eclipse.dzone.com/articles/adding-swt-input-validation-ea" rel="nofollow">this</a> article.

Recommend

  • wicket 1.5 not found error message
  • Dealing with the open/save/cancel dialogue window in IE when using VBA
  • Adding class in table in ckeditor for rails application
  • VBA userform toolbox additional controls dialogue window not showing
  • Java Output right alignment
  • “Big” scrollbar for spinner
  • Displaying field specific validation error messages in jqGrid (server-side validation)
  • Object doesn't support property or method 'valid'
  • Why are pure reducers so important in redux?
  • Is it safe to cast void pointer to char pointer pointer
  • Client-side prediction & server reconciliation
  • Is there a way to read an Excel file using Dataflow
  • How do I get rid of the Eclipse Find/Replace Bar
  • Transparent images in PDF
  • Stored Procedure with multiple IN Parameter
  • Replicating and differentiating portions of a form
  • Android libgdx prefs getting lost
  • Implementing HMAC-SHA256 for Keybase in Javascript
  • composer dependency stating in doesn't have php-xsl
  • OpenCV Python: Draw minAreaRect ( RotatedRect not implemented)
  • WP7 difficulties binding data to listbox itemssource - won't refresh
  • Is there a way to choose which files are displayed to the user via the standard OPENFILE dialogs?
  • Comparing user's facebook/twitter friends to site's users in Python/Django
  • Efficient & Pythonic way of finding all possible sublists of a list in given range and the minim
  • Why can't UI components be accessed from a backgroundworker?
  • python: forcing relative imports to search from script file
  • Recording values of radio buttons in ember
  • Firefox Extension - Monitor refresh and change of tab
  • Alternative to overridePendingTransition() - Android
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • C# - Serializing and deserializing static member
  • How to add date and time under each post in guestbook in google app engine
  • Matrix multiplication with MKL
  • coudnt use logback because of log4j
  • embed rChart in Markdown
  • Does armcc optimizes non-volatile variables with -O0?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app