Limiting JTextField to 4 characters only

I'm making an interface to allow the user to enter 4 groups of 4 digits. This is made up of 4 JTextFields, that when the user has entered the fourth digit in box 1 the interface automatically jumps to box 2 etc, usual stuff. The problem I'm having is with the last box. I've tried to put code into a CaretListener to prevent the user entering more than 4 characters, but if I use a technique like substring to remove the extra character I get a recursion error. I though setColumns was meant to set the limit of characters entered, but I can't get it to work. Does anyone know how I can limit box 4 (txtCode[3]) to 4 characters?
          for (int i = 0; i < txtCode.length; i++)
               txtCode[i] = new JTextField();
               txtCode.setColumns(4);
               final int k = i;
               txtCode[i].addCaretListener(new CaretListener()
               public void caretUpdate(CaretEvent e)
                    if (txtCode[k].getText().length() >= 4)
                         if (k < 3)
                              txtCode[k+1].requestFocus();
                              txtCode[k+1].setCaretPosition(0);

The Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#filter]Text Component Features shows you how to use a DocumentFilter to accomplish this. Or maybe you should use a JFormattedTextField.

Similar Messages

  • After upgrading to Firefox 8.0.1, now on at least one website I use, it limits the number of characters that I can type in a text box to 275, is there a way to fix this?

    After upgrading to Firefox 8.0.1, now on at least one website I use, it limits the number of characters that I can type in a text box to 275, is there a way to fix this?

    That may be part of the coding that the web page is using.
    *https://developer.mozilla.org/en/HTML/element/input

  • Smartform (Bid) with # characters only ?

    Hi guys,
    For some reason, the smartform for the bid displays "#" characters only =( 
    Is this a bug ?
    Regards,
    Diego

    Hi Diego,
    the main objective of this forum is the capitalization of SRM knowledge. A kind of solution database.
    So anybody can try to find responses to his/her issues.
    I would accept that new comers would not find the right thread immediatly.
    But you are not a new comer, and this question was already posted by.... YOU !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    PO without Data ?   (Output with -> ########)
    This would avoid other users loosing their time.
    Rgds
    Christophe

  • Out of 132 characters 84 characters only displayed

    HI,
    I have created text element (TEXT SYMBOL) with 132 max.. characters , but out of this 84 characters only displayed on the selection screen......
    I have used in the program below code,
    SELECTION-SCREEN BEGIN OF BLOCK  A WITH FRAME TITLE TEXT-001. "
    SELECTION-SCREEN END OF BLOCK A.
    Here text symbol text is " Selection Screen sample with Radio Buttons and select the below radio buttons we have given names like the  ALV or LIST or None, see"
    But in this case only  " Selection Screen sample with Radio Buttons and select the below radio buttons we ha" tetx is displaying......on selection screen block area
    Please let me know the reason......
    Thanks,
    Madhu.
    Moderator message: please consult ABAP documentation before asking.
    locked by: Thomas Zloch on Sep 2, 2010 10:53 AM

    Hi,
    Since Release 6.20, a standard width of 120 columns has been defined for the outer frame for text-symbol,but  the width was previously 83 columns before its release.
    The below code shows the text symbol where text-004 = abcdefghijklmnop..... of 132 characters.
    But it will display only 84 characters.
    SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
    SELECTION-SCREEN END OF BLOCK b4.
    so if u want to display entire text it can be viewed on your list ,
    write: text-004.
    This would be helpful.

  • Regular Expression Numeric characters only

    Hi All,
    I'm trying to select just the numeric characters only. However, this regexpression returns data that also has a - in it or alpha characters, such as 58-69-30-008 NWSE. I don't want this.
    I just want rows with ONLY numeric data.
    WHERE servloc like '%[0-9]%'Thanks for your help,
    John

    LPS wrote:
    try this
    where regexp_like(servloc,'[0-9]');The above will return any servloc that has at least one digit. OP asked for "just the numeric characters only". Correct regexp_like would be:
    where regexp_like(servloc,'^[0-9]+$');Or:
    where regexp_like(servloc,'^\d+$');SY.

  • Limiting the number of characters in a JTextField

    Hi I have 6 textfields and I don't want the user to enter more than 160 characters in a tet box. As soon as he reaches that limit, it shouldn't accept any more characters, how do I do this?
    One more thing, incase I register 5 textboxes to listen to the same event, how do I make out which textbox generated the event?
    Thanks

    The event generated from the textboxes has a method e.getSource() check that.
    To limit the number of characters extend PlainDocument and override insertString(...) and check the text size if the old size plus text to be inserted < your limit call super.insertString(..) else return.

  • Limiting Text Box to Alpha Only A-Z using Acrobat 9 Standard

    I'm trying to set a text box in my form to only accept alpha A-Z only.  Can anyone tell me how to go about doing this.  I'm working with Acrobat 9 Standard using a PDF file.  Thanks!

    OK, it's a little more complicated with Standard than it shold be, but begin by adding the following JavaScript to the first page's Page Open event (Pages panel > right-click on first page > Page Properties > Actions > Page Open > Run a JavaScript > Add) :
    // Allow just upperse letter from A to Z
    function alphaOnly_ks() {
        // Get all of the characters that have been entered in to the field
        var value = AFMergeChange(event);
        // Do nothing if field is blank
        if(!value) return;
        // Reject the entry if the entry doesn't match the regular expression
        if(!AFExactMatch(/^[A-Z]+$/, value)) event.rc = false;
    Just copy and paste that entire block of code.
    Now in the text field you need to call this function in the Keystroke event (right-click field with Select Object tool active > Properties > Format tab > Custom format category > Custom Keystroke Script > Edit) like this:
    // Limit this field to uppercase letters from A-Z
    alphaOnly_ks();
    If you only have one page in the document, close the document and reopen it. If there are more than one page, go to a different page and return. This has the effect of loading the script so it is available from the field. If you were using Pro, you could place the function in a document-level JavaScript and avoid this nonsense.
    The field should now only allow entry of uppercase letters from A-Z. It possible to alter the script so that any lowercase letters are automatically converted to uppercase.

  • Preview typing special characters only

    I'm having troubling typing text w/ Preview.
    When I try to type, it only types special characters. I'm thinking if I accidently used some shortcut combination to type special characters.
    It is not letting me type normal language at all now. Does anyone have any idea?
    If there is a way to uninstall preview and reinstall, would anyone let me know? Thanks!!!

    Why is everyone going on about the Character Pallette when most of the required symbols are available from the keyboard?
    Using the option key, these are the standard symbols for US and UK keyboards (lower case followed by upper case with the addition of the shift key) Starting with the numeric row;
    ¡€#¢∞§¶•ªº–≠
    ⁄™‹›fifl‡°·‚—±
    œ∑´®†¥¨^øπ“‘
    Œ„‰ÂÊÁËÈØ∏”’
    åß∂ƒ©˙∆˚¬…æ«
    ÅÍÎÏÌÓÔÒÚÆ»
    `Ω≈ç√∫~µ≤≥÷
    ŸÛÙÇ◊ıˆ˜¯˘¿
    Enable the Keyboard viewer by checking 'show keyboard and character viewer in the menu bar' in System Preferences > Keyboard > keyboard tab.
    Open the keyboard viewer from the flag menu and press the opt key - you'll see all the available symbols and accents. Some of them are highlighted in orange - these can be used with multiple letter combinations.
    For instance, opt+e followed by e = é, opt+e followed by a = á, opt+u followed by o = ö.
    Message was edited by: noondaywitch

  • Can I open multiple tabs in Firefox when WINDOWS starts up? Command line limits to about 204 characters...

    I know how to configure Firefox so that it opens multiple tabs every time you open ''Firefox''. I want it to open multiple tabs when I start ''Windows''. Or in other words, I don't want to connect to multiple web pages every time I open a browser, just the first time I log on for the day.
    I tried appending the web sites in the command line of a Firefox shortcut in my Windows Startup folder. The problem is that in this approach, you're limited to as many URL's as you can type in about 204 characters ('C:\Program Files (x86)\Mozilla Firefox\firefox.exe' uses up 52 of the 256 characters available in a shortcut).
    Is there a way to open more tabbed web sites than that?
    What would be cool is if there was something like a FFstartup.ini file or something, where you could provide a list of websites as long as you want, and it would open them all. So, the command line would look like:
    'C:\Program Files (x86)\Mozilla Firefox\firefox.exe' 'C:\Program Files (x86)\Mozilla Firefox\FFstartup.ini'
    ...and the FFstartup.ini file would look like:
    [Startup]
    'http://www.yahoo.com'
    'http://www.google.com'
    'http://www.firefox.com'
    etc...
    If there's no current way to do this, how would I make this suggestion to be developed?
    Thank you!

    Use a .bat or .cmd file to start Firefox if you need more space than the target line in a shortcut allows.<br />
    Separate the URLs with spaces.
    start "" "C:\Program Files\Mozilla Firefox\firefox.exe" http://www.yahoo.com http://www.google.com http://www.firefox.com
    * https://developer.mozilla.org/en/Command_Line_Options

  • Alert Inbox displays 80 characters only.

    Hi
    I am using a file to mail scenario where i want to display the error text of 1000 characters.
    i am using SALERT_CREATE Function module .
    But i am having the limitation of 80 characters .
    Pls if any body have worked on this scenario can help me out.
    This is not a BPM scenario for information

    HI,
    Can you please check the container element data type which is created in ALRTCATDEF transaction.
    Thnx.
    Chirag Gohil

  • Limited Financial User licenses are only good for two weeks

    I have repeatedly requested a license for a client who, according to their contractual info, both in my records and on the SAP B1 Portal 'Contractual Information' link, has
    3 Professional Users and 3 Limited Financial Users.
    Every time I get a license it is for 6 Professional Users, and it expires in 2 weeks because, so it says, I have exceeded my contractual license limitations.
    I have been working with SAP Support but so far I do not have a fix. With Support, we have repeatedly deleted all previous systems for the client (both as Partner and as Customer S number), created one and only one new system, and submitted the request for 3 Professional Users and 3 Limited Financial Users.
    And it still comes back with 6 Pros that expire in 2 weeks. I know that for now a Pro User is substituted 1 for 1 for the new limited license types, but why can't I get a permanent vs. a temporary 2 week license?
    Please do not write and tell me how to delete a system or how to apply for a license, etc. I know how to do those things and I have walked through the entire process with SAP Support with me via Webex, and we don't get a permanent license.  I just want to know if anybody has successfully got a standard license for the new limited types so I know that the process actually works. (Based on my experience, I don't think the Portal can handle the new license types. ) Then maybe Support and I can focus on a flaw in the contractual info as stored on the site, etc. as the source of my problem.

    Hi Cindy ,
    This is not a normal case. I have a lots of clients who are using limited license and their license are not expired .
    Might be something happening with SAP recently because I haven't requested any license recently .
    I had faced this issue one time when I didn't realise the date of expiration while ordering SAP license but I made correction and import it next time and it worked for me fine .
    I am not sure how can i be of help but this certainly bring my attention and would definely like to know the solution
    Thank you
    Bishal

  • Limitation in amount of characters in lov ?

    Hi.
    Ich habe an updateable report for multirow updates, where i added a "add one row to report" button, to add new rows.
    When adding a row a lov is filled by a query to show me values to choose from.
    Now i got an error "numeric or value error buffer too small", when executing the lov query.
    We found out that the error occurs, when i have lots of characters in my query.
    When query returns around 5000 chars, it works, when ist return 16600 chars, filling the lov in my report column fails.
    Question : Is the any character limitation in the case (updateable report, filling report column that has type "lov filled by query" with lots of data ) ?
    If yes, where is the limit ?
    btw. I am using Apex 3.2
    Greets
    Bernd

    Are you using a Select List to display this LOV? There IS a limitation of Select Lists (but I am not sure what that limit exactly is).
    Try changing the field to a Popup LOV instead.
    Amanda.

  • Sender Mail Adapter ASMA issue - due to limitation of length upto 200 only.

    Hi,
    I have a scenario where i have to pull the emails from the mail server using sender mail adpater with XIPAYLOAD as message protocol.
    Also i am setting the "Set Adapter Setting Messgae Attributes" for retrieving values form header such as SHeaderCC etc..
    I use dynamic config in the mapping to get those values.
    The Scenario works fine, but when the cc length is more that 200, i am not getting any value in the inbound messgae to mapping.
    In SAP help, it says, "The length of the attribute value is defined by the XI message protocol. Values can be a maximum of 200 characters long. If, for example, you assign longer values in the mapping or adapter modules then this can lead to processing errors at runtime or the values are shortened to 200 characters. This shortening can also lead to a processing error. The processing error that occurs depends on the components that access the attributes."
    In my case, the cc is empty if the length is more that 200.
    Any idea how to tackle this issue? I think even writng the sender adapter module wont solve the issue as the any attribute lenght inthe message ehader cannot be greater than 200.
    All ideas are welcome.
    Regards,
    Manikandan R

    Hi
    As you said this error will occur when the mail messages with header attributes containing the values more than 200 chars. By including the adapter module u2013 DynamicConfigurationBean (valuelength) in the configuration part - Advanced you can avoid this error.
    Processing Sequence:
    AF_Modules/DynamicConfigurationBean
    Module Configuration
    dc.valueLength                    200
    Note:
    This module will remove the header attributes if the value is > 200.
    Regards
    Ramg

  • Newly purchased Gujarati font doesn't show Hindi characters, only English.

    I bought Gujarati and Devangari. Devangari works great in my InDesign CS6; Gujarati shows copy in English characters, not Hindi. I am using a Macintosh. The top part of the image is the Devangari type.

    Disregard. The text I import has to be in unicode in order for Gujarati to work.

  • RH 10: TOC hierarchy limited to Books and Pages only?

    I am generating WebHelp on Windows 7 Professional and viewing the generated help in IE 9.
    In the TOC pod it looks like the TOC has only two levels of hierarchy for topics: Books and pages. There does not appear to be a way to add a topic below a page in the TOC hierarchy (a sub page of a page, in other words).
    In the attached sceen shot, a topic is highlighted, and the right pointing arrow is not available.
    Surely RH 10 does not restrict the TOC to just two levels.
    Please let me know how to move a topic to appear under a page in the TOC.
    Thanks.

    Sorry but that's the way it works. You get books and pages. The books contain the pages. If you want topics indented below other topics, you will need to make another book. RoboHelp can help you with this. Right click the page and choose "Create Book from Page" and poof!
    Cheers... Rick

Maybe you are looking for

  • How can I delete a previously published app from my dashboard?

    I have an app on my Windows Store dashboard that was in the store, but I unpublished it and I'll never publish the app again. How can I delete the app from my dashboard? I've read answers on simular questions that an app can't be deleted, but I reall

  • FW800 v eSATA & External Hard Drive set-up questions

    Hi there: I've loosely got 2 questions to the wise here... I recently acquired a new MacBook Pro 17" and have extended my collection of external drives. I have: - 300GB Lacie (connected via FW800) after years of service, now semi-retired used solely

  • Upgrade itunes install new hard drive

    Hi there. Long long time iTunes user here.  A while back I switched off automatic upgrades and have been sitting on version 9.1.1.12 for some time.  I've been meaning to update it ... and now I'd like to do that and more:  upgrade my C hard drive and

  • Low resolution of Google Image Search results in Firefox Android

    I'm new to Android, and I've noticed that Firefox brings up lower resolution Google Image search results in comparison to the same image search on Chrome for Android. When I click on an image result in Firefox it gives me the option of going through

  • Manipulate an uielement in webdynpro abap

    Hi. How I can manipulate an uielement created in time of design (for example, to do visible or not an inputfield) in layout from a method.I´ve seen this code: data: LR_CONTAINER type ref to L_WD_UIELEMENT_CONTAINER, LR_BUTTON type ref to CL_WD_BUTTON