Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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
Song David is currently offline Song David
Messages: 185
Registered: April 2011
Senior Member
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
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
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


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
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
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
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
Song David is currently offline Song David
Messages: 185
Registered: April 2011
Senior Member
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
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
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.


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Previous Topic:Xulrunner based Browser clears cache on startup
Next Topic:Multiline TreeItems
Goto Forum:
  


Current Time: Fri Jul 25 03:04:41 EDT 2014

Powered by FUDForum. Page generated in 0.01511 seconds