Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How can I set text limit per byte size on Text widget?(Text::setTextLimit() does not block text per byte size)
How can I set text limit per byte size on Text widget? [message #800067] Thu, 16 February 2012 16:42 Go to next message
Page Mising name is currently offline Page Mising nameFriend
Messages: 31
Registered: July 2009
Member
Looks like Text::setTextLimit() does not block text per byte size, but by character size. This causes a problem for us with multi-byte languages. I am looking for a workaround how to block the input per byte size in Text widget.

The attached file is a simple example to demonstrate the issue.

With EN locale, the character size is same as byte size.
With JP locale, each JP char is two bytes.

Here is the output from the uploaded sample:
Locale is ja_JP Text is: <とうとして> textLength=5 byteSize=10
Locale is en_US Text is: <TestM> textLength=5 byteSize=5

I tested it on Win XP. [To use JP locale, need to use control panel to set the language.]

Any suggestions is greatly appreciated.

Thanks.
Page
Re: How can I set text limit per byte size on Text widget? [message #809857 is a reply to message #800067] Wed, 29 February 2012 11:05 Go to previous messageGo to next message
Veselin Markov is currently offline Veselin MarkovFriend
Messages: 15
Registered: February 2012
Junior Member
Hello Page,

as I understand your question, you want that your text doesn't get larger than a certain size (in bytes). I suggest using a verify listener on your
org.eclipse.swt.widgets.Text
. Use
org.eclipse.swt.widgets.Text.addVerifyListener(VerifyListener listener)
and implement your own VerifyListener that checks the byte syze of the input text. Here is how one could look like:
private class NumberFieldVerifiyer implements VerifyListener {
	public void verifyText(VerifyEvent 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')) {
				e.doit = false;
				return;
			}
		}
	}
}


Ofcourse you have to adapt it for your case.

Hope that helped.
Veselin
Re: How can I set text limit per byte size on Text widget? [message #810179 is a reply to message #809857] Wed, 29 February 2012 20:02 Go to previous message
Page Mising name is currently offline Page Mising nameFriend
Messages: 31
Registered: July 2009
Member
Thanks. I will give it a try.
Previous Topic:ExpandItem Text Size won't change on Linux
Next Topic:WANTED: Table content changed event
Goto Forum:
  


Current Time: Fri Apr 19 20:15:38 GMT 2024

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

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

Back to the top