|
-
September 11th, 2008, 12:04 AM
#1
Filterning Input Length
I'm using the JFormattedTextField.
I set it document filter to my specific size, it works with normal alpha numeric character.
My problem right now is when the input is a combination of Japanese characters and alphabet.
My textfield needs only to accept 26 bytes,so
right now Im using the getBytes() functionality to control the bytes input.
Using the "InputMethodTextChangeEvent" , if the condition is satisfied, then I would consume the event and commit the text
Code:
private void jText_InputMethodTextChanged(java.awt.event.InputMethodEvent evt)
{
if( this.jText_01.getText().getBytes().length == 26 )
{
System.out.println("Consuming Event");
evt.consume();
try
{
System.out.println("Committing ... ");
this.jText_01.commitEdit();
}
catch(Exception e)
{
System.out.println(e.getCause().toString());
}
}
}
what i want to do, is that when I commitEdit(), I want to flushed the Input Stream to get rid of unnecessary string. Is there a way to do this?
-
September 11th, 2008, 07:13 AM
#2
Re: Filterning Input Length
if jText_01 is a JFormattedTextField object then it has a setText() method that it inherits from JTextComponent. Have you tried to call this method and pass it ""?
-
September 11th, 2008, 08:34 AM
#3
Re: Filterning Input Length
I don't really understand what your problem is - if you want to limit input to 26 bytes, use a DocumentFilter. Where does InputStream come into it?
Are you quite sure you want to measure this in bytes? Java uses Unicode characters, which are multi-byte...
No matter how far down the wrong road you have gone, turn back now...
Turkish proverb
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
September 11th, 2008, 10:18 PM
#4
Re: Filterning Input Length
as I have mentioned the DocumentFilter works well if the character encoding is ROMAN Letters.
the problem is when the input FULL_WIDTH, JAPANESE CHARACTERS.
example you have the same string below:
String strNormal = new String("12345");
String strJapn = new String("12345");
if you get the string length for both string, it will both return size = 5, but if you get the byte length
strNormal = 5
strJapn = 10
so since, input is limited to 26 , for strNormal you can still input 11 more characters
but for strJapn , if you are going to continue inputing Japanese charatecters you can only input 8 more japanese characters
and then there is also a combination of both alphanumeric and japanese characters .
somehow we were able to control the input, using the keypressed, keyrelease, and inputMethodTextChange events..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|