Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2004

Tip: Looking for answers? Try searching our database.

Problems restricting length of Japanese input in JTextField

Thread view: 
Christian Kindler - 13 Sep 2004 10:09 GMT
Hi all.

I have problems problems restricting length of Japanese input
in JTextField. I use the following Document for restricting
the input length:

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class CheckLengthDocument extends PlainDocument {

    private int numberOfChars = 0;

    public CheckLengthDocument(int c) {
        this.numberOfChars = c;
    }

    public void insertString(int offset, String str, AttributeSet
    attributeSet)
            throws BadLocationException {

        int capacity = this.numberOfChars + 1 - getContent().length();
        if (capacity >= str.length()) {
            super.insertString(offset, str, attributeSet);
        } else {
            super.insertString(offset, str.substring(0, capacity),
               attributeSet);
        }
    }
}

This document works fine with normal characters, but when entering
Japanese characters I can still enter characters when the maximum
length is reached and the newly entered characters overwrite the
previously entered characters. Of course this is not what I want.

How can I make this work correctly?

I am using JDK 1.3.1 on Windows2k/WindowsME. Switching to JDK
1.4/1.5 is not an option at the moment.

Christian
berlin123456 - 24 Sep 2004 21:18 GMT
Hello,

I have the same issue too.  I searched all over, couldn't find any answer.
I "kind" solved the problem from the debugging data.  Here is what I do,
inside the insertString method, when the AttributSet is not null, you want
the information to pass (do super.insertString).  Only when the
insertString is null, do your logics.  I have no fact to support what I am
doing and couldn't find any answer on the web.  Hope this is helpful to
you.  If you have found a different answer, please post and let me know.
Thanks.

Berlin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.