CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2005
    Location
    Ellesmera
    Posts
    427

    Question 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?
    *** Con Tu Adios, Te Llevas, Mi Corazon***

    Traveling Encoder...

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    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 ""?

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    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.

  4. #4
    Join Date
    May 2005
    Location
    Ellesmera
    Posts
    427

    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..
    *** Con Tu Adios, Te Llevas, Mi Corazon***

    Traveling Encoder...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured