How can i limit the user to enter only A to Z and space in JFormattedText

dear
i want to use JFormatedTextField in two manners
1.Limit the no of charecters.means in a text field only 20 charecters r allowed.
2.and also check the enterd charecter must be a to z and space not other chareters r allowed.
3.same for numbers means 0 to 9 and decimal.
how can i do by using the JFormated TextFilef.

Probably lacks in some cases but what the hell.
* Filename:           JSMaskedTextField.java
* Creation date:      22-mei-2004
* Author:                Kevin Pors
package jsupport.swingext;
import java.awt.event.KeyEvent;
import java.util.Arrays;
import javax.swing.JTextField;
* A masked textfield is a textfield which allows only a specific mask of
* characters to be typed. If characters typed do not occur in the mask
* provided, the typed character will not be 'written' at all. The default mask
* for this <code>JSMaskedTextField</code> is <code>MASK_ALPHA_NUMERIC</code>
* @author Kevin Pors
* @version 1.32
public class JSMaskedTextField extends JTextField {
    /** Masking for alphabetical lowercase characters only. */
    public static final String MASK_ALPHA_LCASE = "abcdefghijklmnopqrstuvwxyz ";
    /** Masking for alpha-numeric characters (lcase/ucase) only. */
    public static final String MASK_ALPHA_NUMERIC = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    /** Masking for alphabetical uppercase characters only. */
    public static final String MASK_ALPHA_UCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    /** Masking for numbers only. */
    public static final String MASK_NUMERIC = "0123456789";
    /** Masking for hexadecimals. */
    public static final String MASK_HEXADECIMAL = "0123456789ABCDEF";
     * An array of keyevent constants defining which keys are always to be
     * allowed, no matter what.
    private final int[] ALWAYS_ALLOWED = new int[] { KeyEvent.VK_BACK_SPACE,
            KeyEvent.VK_DELETE, KeyEvent.VK_UP, KeyEvent.VK_DOWN,
            KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_SHIFT,
            KeyEvent.VK_HOME, KeyEvent.VK_END};
    /** Boolean specifying whether casing should be ignored. */
    private boolean ignoringCase = true;
    /** Specifying whether the maskin is enabled */
    private boolean isMaskingEnabled = true;
    /** The mask for the textfield. */
    private String mask = MASK_ALPHA_NUMERIC;
     * Creates a default number field.
    public JSMaskedTextField() {
        super(null, null, 0);
        Arrays.sort(ALWAYS_ALLOWED);
     * Creates a number field, with a specified number of columns.
     * @param columns The columnnumber.
    public JSMaskedTextField(int columns) {
        super(null, null, columns);
        Arrays.sort(ALWAYS_ALLOWED);
     * Creates a JSMaskedTextField with a masking.
     * @param mask The masking to be used.
    public JSMaskedTextField(String mask) {
        super(null, null, 0);
        Arrays.sort(ALWAYS_ALLOWED);
        setMask(mask);
     * Gets the masking for this masked textfield.
     * @return Returns the mask.
    public String getMask() {
        return this.mask;
     * Gets whether this JSMaskedTextField should be ignoring casing.
     * @return Returns if the component should be ignoring casing.
    public boolean isIgnoringCase() {
        return this.ignoringCase;
     * Checks whether masking is enabled. Default should be true.
     * @return Returns true if masking is enabled, false if not.
    public boolean isMaskingEnabled() {
        return this.isMaskingEnabled;
     * Sets whether it should be ignoring casing when checking for alpha-chars.
     * @param ignoringCase The ignoringCase to set.
    public void setIgnoringCase(boolean ignoringCase) {
        this.ignoringCase = ignoringCase;
     * Sets the masking for this textfield. The masking will determine which
     * characters can be typed. If the characters in de <code>mask</code> do
     * not occur in the typed character, it won't be typed.
     * @param mask The mask to set.
    public void setMask(String mask) {
        this.mask = mask;
     * Sets the masking enabled. If <code>false</code> this component will
     * behave just like a normal textfield.
     * @param isMaskingEnabled true if masking should be enabled.
    public void setMaskingEnabled(boolean isMaskingEnabled) {
        this.isMaskingEnabled = isMaskingEnabled;
     * Sets text of this textfield. If the blah blah.
     * @see javax.swing.text.JTextComponent#setText(java.lang.String)
    public void setText(String text) {
        for (int i = 0; i < text.length(); i++) {
            if (getMask().indexOf(text.charAt(i)) < 0) { // does not occur
                return;
        super.setText(text);
     * @see javax.swing.JComponent#processKeyEvent(java.awt.event.KeyEvent)
    protected void processKeyEvent(KeyEvent e) {
        if (!isMaskingEnabled()) {
            return;
        char typed = e.getKeyChar();
        int code = e.getKeyCode();
        for (int i = 0; i < ALWAYS_ALLOWED.length; i++) {
            if (ALWAYS_ALLOWED[i] == code) {
                super.processKeyEvent(e);
                return;
        if (typed == KeyEvent.VK_BACK_SPACE) {
            super.processKeyEvent(e);
        if (isIgnoringCase()) {
            String tString = new String(typed + "");
            String ucase = tString.toUpperCase();
            String lcase = tString.toLowerCase();
            if (getMask().indexOf(ucase) < 0 || getMask().indexOf(lcase) < 0) {
                e.consume();
            } else {
                super.processKeyEvent(e);
                return;
        } else { // not ignoring casing
            if (getMask().indexOf(typed) < 0) {
                e.consume();
            } else {
                super.processKeyEvent(e);
}

Similar Messages

  • How can I remove the Apple ID authorization only on one computer and authorize another in his place?

    how can I remove the Apple ID authorization only on one computer and authorize another in his place?

    De-authorize the computer in question.
    Then authorize the new computer.
    Or de-authorize all computers and authorize only the ones that actually exist.

  • How can I limit the User not to create OPPT for a given BP grouping

    Hi ,
    We did create a Business Partner grouping (BUT000-BU_GROUP) and wish to block the user to create an Opportunity ( Transaction Type OPPT ) for this Business Partner grouping ?
    How can we do that ?

    Hi,
    You can do this with the help of BADI
    Customer Relationship Management  Transactions  Settings for Opportunities  Business Add-Ins  Business Add-In for Opportunity: Header Data
    You will have to do enhancements for opportunity header data.
    Please use the BADI : CRM_OPPORT_H_BADI:
    In this BADI use the method : CRM_OPPORT_H_CHECK
    With this you can carry out additional checks - the results of these checks can be copied as error messages. Here you can check the grouping of the business partner you are entering in the transaction and if e.g. grouping of the BP is u201CXu201D the error message can be triggered u201COpportunity can not be created for this BPu201D.
    Please let me know if this helped in resolving your problem
    Regards
    Dinesh

  • How to restrict the user to enter only numeric values in a input field

    How to restrict the user to enter only numeric values in a input field.
    For example,
    i have an input field in that i would like to enter
    only numeric values. no special characters,alphabets .
    reply ASAP

    Hi Venuthurupalli,
    As valery has said once you select the value to be of type integer,once you perform an action it will be validated and error message that non numeric characters are there will be shown. If you want to set additional constraints like max value, min value etc you can use simple types for it.
    On the project structure on left hand side under local dictionary ->datatypes->simple types create a simple type of type integer
    The attribute which you are binding to value property ;make its type as simple type which you made
    Hope this helps you
    Regards
    Rohit

  • How can we prevent a user from entering a value in Parameter Field?

    how can we prevent a user from entering a value in Parameter Field and Select-options Field?

    make it invisible, make it inactive, make it display only.
    if the field is not there or not to be seen the user WILL have problems inputting data.
    BUT once the field is there you can NOT prevent that the user fills it with data.
    all you can do is on PAI check if the data the user inputted was good or bad, and clear his inputs, but you can NOT prevent him inputting something.

  • How can I find the USer Exit...

    Hi,
    How can I find the USer Exit...
    I need to do changes for this User Exit :EXIT_SAPLKEII_002
    In which T-code I can open this Exit
    Ex: Go to some Transcation code and then give the name of the Exit ato access this Exit
    ...any sugesstions will be apprecaited!
    Thanks & Regards,
    Kittu

    Hi,
        the EXIT : EXIT_SAPLKEII_002 is the exit,in this SAPLKEII is the standard Program.Copy this program and go to transactio SE38 and press Enter and then go for the option Where used list and check the check box Transaction. It displays the possible Transactions that the Exit triggers
    Regards,
    Vijaya Lakshmi.T

  • How can I limit the number of emails retained on my ipad air?

    How can I limit the number of emails that are retained on my iPad Air?  Because of legal requirements of a long-term project, I cannot permanently delete emails relating to that project from my ISP's mail server.  My gmail account contains over 17,000 emails and, upon setting up my new iPad, and updating to ios 7.1.1, I now have all 17,000+ emails taking up space.  I would like to limit the emails by count as I was able to do on my old iPad running ios 5.1.1 OR to retain them based on date range.  I have not found any instructions on the support discussions or general iPad blogs that allow me to do that.  Any way around this problem?
    I also miss the 5.1.1 mail search feature that allowed me to narrow the search by from/to/subject/all.  Does anyone know if that feature is available using some little-known ios 7.1.1 feature?
    Thanks for your help.

    jlfcba wrote:
    IOS 7.1.1 doesn't show a "days to sync" parameter anywhere in SETTINGS/Mail,Contacts,Calendars/ACCOUNTS/GMAIL Account/ GMAIL Acccount Info.  There is nothing in iTunes relating to such an option either.  So, it seems I'm back to square one.
    If you have a decent mail provider like Microsoft Hotmail or Outlook.com mail it does.
    If you have Gmail it does not.  Quite right. Gmail is rubbish.

  • HT2729 I have limited space on my new ipad. How can I limit the number of songs from my itunes on my imac from going to my ipad when I connect the two?

    I have limited space on my new ipad. How can I limit the number of songs from my itunes on my imac from going to my ipad when I connect the two?

    you can do this by keeping the external hard drive connected and doing the following
    -hold shift key down on computer while opening iTunes and a prompt will appear to choose a library
    -select choose library, iTunes should bring up your explorer windows where you can search for the external HD
    -after you find the external HD find the iTunes folder you just copied to it
    -after opening the iTunes folder look for the file that says iTunes library.itl or if you can't see that extenstion just look for a document looking thing in the iTunes folder that shows up as a database file
    -double click the database file and boom iTunes should load your library without having to copy it to the computer
    PS: do make sure that if you are going to do it this way, make sure that the external HD is connected at all times, because if you don't then you will get exclamation marks next to your iTunes songs
    double PS: if you are unsure how to find out if the iTunes library file is a database file just right click it and choose properties and under the type it should say database file
    hope this helps:)

  • Hi, how can I limit the number of emails I can see on my iPhone 5. Every time in delete one and older email gets added from my live.co.uk account (where I want to keep my 2500 emails) I just don't want many on my phone. Thanks

    Hi, how can I limit the number of emails I can see on my iPhone 5. Every time in delete one and older email gets added from my live.co.uk account (where I want to keep my 2500 emails) I just don't want many on my phone. Thanks

    You can't. Why on earth would you attempt to manage 2500 emails with setting up a folder structure or some means of doing so? Simply keeping them in an single inbox is not realistic, no matter what email client you use.

  • HT201342 How can I change the USER of my i-cloud address? My 12 year old set up the e-mail account and used a silly user name (like: turtle!!). I would like to have an icloud e-mail account but under my own user name. The other /old name can be deleted?

    How can I change the USER name of my i-cloud e-mail account? It was set up by my son and he used a silly / embarrassing user name. I would like to change this name OR set up another i-cloud e-mail account under my own name / reference. Help?

    iCloud email addresses can't be changed or deleted, but you can set up an alias namethat he can use which will be linked to his current iCloud account and will receive email in the existing iCould inbox.  This guide explains how: http://support.apple.com/kb/PH2622.

  • How can  I  restrain the user login portal once, in the same time ???

    Hi
    I need to restrain the user can't repeat to login portal ....
    to reduce portal loading
    How can I restrain the user login portal once, in the same time???
    Which attributs in Identity Manager or amconsole I can do it to restrain the user ??
    tks

    Does your portal support anonymous access? If so, make sure you are using the authlessanonymous mode. This mode only creates one session that is shared for all anonymous users. This is much more efficient than anonymous access, which creates a session for each anonymous user.
    I have no other recommendation for limiting users to a single login. In general, web applications do not behave like this. What if a user closes their browser without logging out? Does the user have to wait until the session times out in order to log back in again?
    The same thing is true for users that are mobile. If a user leaves their office without logging out and then attempts to log in with a laptop in the conference room, then access will be denied in your implementation. Users do not expect this type of limitation being built into the system.
    If you are having problems scaling, then you need to look at your architecture and perhaps add some more resources. Also, make sure you are making efficient use of the authlessanonymous access mode as stated above.
    - Jim

  • The Ipad2 Application Data folder is taking up huge space in C: Drive. How can I shift the User Application data for iPad2 to another Drive?

    The Ipad2 Application Data folder is taking up huge space in C: Drive. How can I shift the User Application data for iPad2 to another Drive?

    Thanks a lot for the response. Yes, I am checking my C: drive data thoroughly now, including the hidden folders, to ascertain if something else can be moved, as per your suggestion.

  • How can I limit the number of rows returned by a select stat

    How can I limit the number of rows returned by a select
    statement. I have a query where I return the number of stores
    that are located in a given area.. I only want to return the
    first twenty-five stores. In some instances there may be over
    200 stores in a given location.
    I know is SQL 7 that I can set the pagesize to be 25....
    Anything similiar in Oracle 8i?
    null

    Debbie (guest) wrote:
    : Chad Nale (guest) wrote:
    : : How can I limit the number of rows returned by a select
    : : statement. I have a query where I return the number of
    : stores
    : : that are located in a given area.. I only want to return the
    : : first twenty-five stores. In some instances there may be
    : over
    : : 200 stores in a given location.
    : : I know is SQL 7 that I can set the pagesize to be 25....
    : : Anything similiar in Oracle 8i?
    : If you are in Sql*Plus, you could add the statement
    : WHERE rownum <= 25
    : Used together with an appropriate ORDER BY you
    : could get the first 25 stores.
    Watch out. ROWNUM is run before ORDER BY so this would only
    order the 25 selected
    null

  • How can i receive the user name of the present operating system

    HI,all.
    how can i receive the user name of the present operating system from SAP.Have any funciton to use?Thankyou!

    use sy-uname system field.
    report ztest.
    write:sy-uname.
    thanks.
    reward if solved.

  • How can I limit the number of emails resident in Apple Mail?

    How can I limit the number of emails resident in Apple Mail inbox?

    jlfcba wrote:
    IOS 7.1.1 doesn't show a "days to sync" parameter anywhere in SETTINGS/Mail,Contacts,Calendars/ACCOUNTS/GMAIL Account/ GMAIL Acccount Info.  There is nothing in iTunes relating to such an option either.  So, it seems I'm back to square one.
    If you have a decent mail provider like Microsoft Hotmail or Outlook.com mail it does.
    If you have Gmail it does not.  Quite right. Gmail is rubbish.

Maybe you are looking for