Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » how to let users only input money number into text widget?
how to let users only input money number into text widget? [message #730059] Tue, 27 September 2011 10:50 Go to next message
Eclipse UserFriend
hi all,

how to let users only input money number into text widget?

thanks a lot
David
Re: how to let users only input money number into text widget? [message #730298 is a reply to message #730059] Wed, 28 September 2011 02:04 Go to previous messageGo to next message
Eclipse UserFriend
This would help

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19.java
Re: how to let users only input money number into text widget? [message #730300 is a reply to message #730059] Wed, 28 September 2011 02:07 Go to previous messageGo to next message
Eclipse UserFriend
On 2011-09-27 16:50, micromms wrote:
> hi all,
>
> how to let users only input money number into text widget?

Add a VerifyListener and set the doit member of the event argument to
false, if the current input is wrong (Other members of the event object
allow you to retrieve the current content.

See

http://www.java-tips.org/other-api-tips/eclipse/how-to-validate-swt-text-controls.html
http://www.java2s.com/Code/JavaAPI/org.eclipse.swt.widgets/TextaddVerifyListenerVerifyListenerlis.htm

for examples.

HTH & Greetings from Bremen,

Daniel Krügler
Re: how to let users only input money number into text widget? [message #730446 is a reply to message #730300] Wed, 28 September 2011 08:35 Go to previous messageGo to next message
Eclipse UserFriend
thanks for help, but my question is how to do with CURRENCY ONLY,
text.addListener(SWT.Verify, new Listener() {
			public void handleEvent(Event e) {
				String string = e.text;
				
				char[] chars = new char[string.length()];
				
				string.getChars(0, chars.length, chars, 0);
				
				for (int i = 0; i < chars.length; i++) {
					if (!('0' <= chars[i] && chars[i] <= '9' || chars[i]=='.')) {
						e.doit = false;
						return;
					}
				}
			}
		});

decimal fraction is alowed in above code, that is , the users can input 29.5646 or 29.234.456.567,
how to do like this 29.23 or 29.2 or 29?

Thank you very much
David
Re: how to let users only input money number into text widget? [message #730754 is a reply to message #730446] Thu, 29 September 2011 00:44 Go to previous message
Eclipse UserFriend
Its a matter of logic,
you have to use regular expression to validate the input string using Pattern class of java.

Search google for currency regular expressions and select the expression which suites you best.
Previous Topic:Xulrunner based Browser clears cache on startup
Next Topic:Multiline TreeItems
Goto Forum:
  


Current Time: Thu Jul 24 12:42:22 EDT 2025

Powered by FUDForum. Page generated in 0.03698 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top