Praoblem with backspace in jtextfiled

Hi friends,
I need to validated the textfiled as only allow Alphabets and not allow any other charecters.. I have no prob with this prog and its work well but when user try to edit in the textfield, both backspace and delete buttons is not working.. Anyone tell me how to enable the keys in textfiled (Note : Even I found ascii value for backspace button and I used it but not working)........
private void jTextField1KeyTyped(java.awt.event.KeyEvent evt)
String value = jTextField1.getText();
int l = value.length();
if ((evt.getKeyChar() >= 'a' && evt.getKeyChar() <= 'z') || (evt.getKeyChar() >= 'A' && evt.getKeyChar() <= 'Z') || (evt.getKeyCode()==08) )
jTextField1.setEditable(true);
jLabel1.setText("");
} else {
jTextField1.setEditable(false);
jLabel1.setText("Enter only ALPHABETS");
if(l==10)
jTextField1.setFocusable(false);
jLabel1.setText("Enter only 10");
else
jLabel1.setText(" ");
Thanks in advance,
Jack..

Also, don't post code that doesn't compile (unless your problem is that it doesn't compile).(evt.getKeyCode()==08) Octal 08 is illegal and doesn't compile.
Even I found ascii value for backspace button and I used it And which Java learning resource advised that? (so we can know to steer other newbies away from it)
I need to validated the textfiled as only allow Alphabets and not allow any other charecters.So use a DocumentFilter, not a KeyListener
db

Similar Messages

  • Problem with backspace on JFrame

    Hello,
    I have a problem on a JFrame. Indeed, I add a keyListener to the frame, but the "Bakcspace" don't work. There is anything when a I press on Backspace (with KeyTyped, KeyReleased and KeyPressed). All other keys are working.
    Thanks.

    the solution of the problem is :
    Version note: This page reflects the focus API introduced in released 1.4. As of that release, the focus subsystem consumes focus traversal keys, such as Tab and Shift Tab. If you need to prevent the focus traversal keys from being consumed, you can call
    component.setFocusTraversalKeysEnabled(false)
    on the component that is firing the key events. Your program must then handle focus traversal on its own. Alternatively, you can use a KeyEventDispatcher to pre-listen to all key events. The focus page (in the Creating a GUI with JFC/Swing trail) has detailed information on the focus subsystem.

  • Problem with backspace

    Please help with this small problem have been coding a calculator program for several weeks and have everything working except the backspace button would really appreciate some help the code for my action performed class which would contain the code is posted below thanks in advance
         public void actionPerformed(ActionEvent e){
                   char currentOperator;
                   String newNumberField = newTextField.getText();
                   if(!beenBefore){
                        num1 = new Integer(newNumberField).intValue();
                        lastOperator = e.getActionCommand().charAt(0);
                        currentOperator = e.getActionCommand().charAt(0);
                        beenBefore = true;
                   else{
                        num2 = new Integer(newNumberField).intValue();
                        currentOperator = e.getActionCommand().charAt(0);
                        switch(lastOperator){
                             case '+': num1 = num1+num2;
                                         break;
                             case '-': num1 = num1-num2;
                                         break;
                             case '*': num1 = num1*num2;
                                         break;
                             case '/': num1 = num1/num2;
                                         break;
                        lastOperator = currentOperator;
                   if(currentOperator == '=')
                        newTextField.setText(String.valueOf(num1));
                   else
                        newTextField.setText("");
                   if(currentOperator == 'C')
                        beenBefore = false;
                if(e.getActionCommand().equals("1/x"))
                      newTextField.setText(String.valueOf(1/num1));
                  if (e.getActionCommand().equals("Backspace"))

    why even bother posting a reply if ur goin to be like that I'v tried several methods keep getting errors heres one I tried
    if (e.getActionCommand().equals("Backspace")
      String.valueOf(num1) = String.valueOf(num1)(0, String.valueOf(num1) - 1);I'm only looking for some help man an it aint homework either whats ur problem

  • How to force focus last focused HTML input element when going back in history with backspace?

    SUMMARY: I am a Firefox user with HTML knowledge. I want to be able to configure Firefox to behave in a special manner when I hit backspace. It's something that Firefox already does, BUT NOT ALWAYS. I don't know why it behaves differently in different situations for no apparent reason. I want to be able to configure firefox to ALWAYS behave in the manner I want to. Read below for the precise description.
    When I fill a FORM in a page, wether POST or GET, and press ENTER, it obviously acts as expected: submits the data and brings me to a new page. When I get to the new page, and I press BACKSPACE, Firefox behaves in sometimes like TYPE 1 and sometimes like TYPE 2 (see below), and I can't predict which one he will choose. I want to be able to configure it to behave ALWAYS like TYPE 2.
    TYPE 1 - Firefox reloads the previous page, as if I just entered it for the first time.
    TYPE 2 - Firefox brings me back to the exact same page view I had before pressing ENTER to submit the FORM.
    2.1 - It doesn't reload the page;
    2.2 - It places the page in the same scrolled position I was before (for example, if I scrolled to the bottom of the page to fill the FORM and press enter, after pressing backspace it brings me to the bottom of the page again;
    2.3 - It automatically focus the HTML input element I last typed (the element that was focused at the very moment I pressed ENTER to submit the FORM).
    So, I want to be able to configure Firefox for it to ALWAYS BEHAVE LIKE TYPE 2 whenever I fill a HTML FORM, press ENTER and press backspace after going to the new page. All three details I gave are important. Remember that I've already experienced TYPE 2 in previous versions of Firefox, I just wish to FORCE IT to behave like that ALWAYS (because for no apparent reason, sometimes it behaves like TYPE 1 instead).
    Please let me know if that's possible, and if not, I would really THANK YOU ALL FOREVER if you add this feature to the next version.

    It's set to true.
    I saw the add on you suggested, but it does not fulfill my needs.
    I like the behavior exactly as I said because, after submitting the form, I want to be able to look something in the new page and quickly get back to the form, change the text I wrote in the input element and submit it again, in a matter of one or two seconds only...
    I was able to do that whenever firefox behaved like TYPE 2 (explained above)...
    Thanks for the reply but didn't solve my problem yet...

  • SAPScript PC Editor - Line Repeats with Backspace key

    In a transaction entering text data that is using the Word-Processing SAPScript PC Editor.  When data is entered above the existed text, the line wraps onto another line and if the backspace is used to the first position, the line repeats.
    The form that is being used from the path Format &#61664; Change Format is ‘S_DOCU_SHOW’.
    Is there a way not to have the line repeat if the backspace is used?
    Thank you,

    I just looked at that template. Just double click the "name" text, all 3 lines will highlight; then just type your name and address. Do the same with what you want to put in the other block on the left side. On the additional pages, a single click on the Character Name will highlight it enabling you to type in "Sam Jones" and in the dialog paragraph, the same: single click, type dialog. No need to use the delete key at all (unless you make a mistake). It will help if you Show Invisibles (ShiftCmndI).
    Walt

  • Problems with backspace in ServiceDesigner on IBM

    Hi
    Running ias9i we 1.1.
    When using the ServiceDesigner on a ex. Dell the backspace key functions fine, but when running on an IBM pc / laptop the backspace key do not function.
    Please advise
    null

    Hi,
    check that you aren't using JDK 1.3 on the IBM laptop.

  • Problem with backspace on Iphone 4.

    I have an Iphone 4 and I can't insert a word without deleting the entire sentence.

    Start at the bottom of page 25 "Editing Text":
    The User Guide is available at http://support.apple.com/manuals/ or downloadable from iTunes as an iBook.

  • After recovery, admin password filled in with "dots" and cannot delete or change it

    Hello.
    I ran the Windows 7 updates yesterday, but only the necessary ones.  I did not install any of the optional ones.  After the updates completed, I turned the computer on and it was stuck in a loop cycle - starting windows, then the admin password log in box came up.  The box was fiiled in (with "dots" but too many to represent my password) and the screen just quickly flashed back & forth between the log in screen and "password incorrect".     I tried to switch user, and it flashed back to the admin log in. 
    I did a system recovery to factory defaults (after backing up all data)  using the recovery discs.  After recovery, the "Set a password for account" screen comes up with the box below "Type a password" filled in completely with dots.  I cannot erase them with the backspace or delete keys.  If I highlight it and then try erase it with backspace or delete, the cursor just moves to the right hand side of the password box, but it still doesn't delete the faulty password "dots" so that I can change it. 
    I tried to reboot by holding in the power button and then turning it back on.  After selecting country & language again, the same password screen come up.
    It is stuck!  Any help would be greatly appreciated!  I computer I have  is the HP TouchSmart 310 PC 1155-Y.
    Thank You!
    This question was solved.
    View Solution.

    That is curious with a Recovery.  First, try to reset the password using NTPassword.  Make the CD, boot to it  following the directions.  If that does not solve the signon problem, consider installing the OS from a regular Windows 7 disk of the same version, using the key from the COA sticker.
    {---------- Please click the "Thumbs Up" to say thanks for helping.
    Please click "Accept As Solution" if my help has solved your problem. ----------}
    This is a user supported forum. I am a volunteer and I do not work for HP.

  • No major shortcomings keyboard arrow key. even if the text part of the message you clicked the arrow keys to update the screen would be great. with an update on my idea, and so it would be more useful

    no major shortcomings keyboard arrow key. even if the text part of the message you clicked the arrow keys to update the screen would be great. with an update on my idea, and so it would be more useful

    greghcrash wrote:
    It Would be great to have keys on the onscreen keyboard.
    Such as a computer keyboard.
    With BACKSPACE, TAB WITH SETTINGS, DELETE, TYPE OF TYPE, BOLD TYPE, UNDERLINE ETC....
    I HAVE A KEYBOARD COVER AND IF I NEED TO USE CERTAIN KEYS I HAVE TO SWITCH TO MY KEYBOARD CASE AND THAT IS VERY INCONVENIENT.
    IT IS ALSO A TIME WASTER.
    When you installed iOS 8 did you read about the new features? Applications can create custom keyboards…
    http://www.imore.com/custom-keyboards-ios-8-explained
    You need to look for an app that has a custom keyboard with the features you require, I suggest you find one without CAPSLOCK
    greghcrash wrote:
    IT IS ALSO AGGRAVATING WHEN TYPING AND IT AUTOMATICALLY CHANGES THE WORDS THAT YOU WANT TO USE.
    THANK YOU FOR YOUR TIME
    Again you need to look at how to manage the device - these settings can be turned off already & you can edit the 'suggestions' too.
    Settings > General > Keyboards > turn Auto-Correction Off.
    Sadly you cannot disable autocorrect temporarily, so it's all or nothing.

  • Backspace deletes blank spaces

    I notice a strange and irritating behaviour in Pages 1.7.2, Numbers 1.7.3 and Keynote 1.7.2:
    If I delete characters with backspace and delete the last character of a word, that space before the character is deleted as well.
    Example:
    Text: "hello wo". Press Backspace, text: "hello w". Press backspace again, text: "hello" ('w' and space deleted in one step).
    if you use the onscreen keyboard, that might help. If you use an external bluetooth keyboard, the deletion of the space is pretty annoing. The behaviour is pretty new. Can it be switched off?
    Please help. I am writing a novel on my iPad and *hate* to insert the missing blank again and again.
    Thanx,
    Goetz
    P.S.: In other apps (such as iCal, Mail etc.) backspace works normal. It must be an iWork-thing

    My ID version is CS6 for my Mac OS X 10.8.4. In a multi-column story, one column might run all the way to the bottom of the text box, while the next is four lines short and the next is two lines short. Screen shots are provided

  • Updating textfield with DEL key not taking into account

    I have a decimal field which accepts only numerals...
    after modifying the value in the field and pressing an OK button...the new value is reflected in a table...
    but if i modify the same field value using the "delete" key and press OK...the new value is not taken into account....
    but the same works with "backspace" key...
    So do i need to set anything to respond to del key...
    Thanks

    Also i am not able to put the code here as it is a huge applicationI did not ask for your entire application. I asked for
    demo code means code that we can compile and execute, but it only contains the code relevant to your problem
    Here is an example:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class DemoCode extends JFrame
         JTextField textField;
         public DemoCode()
              textField = new JTextField();
              getContentPane().add(textField, BorderLayout.NORTH);
              JButton button = new JButton("Update Database");
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        System.out.println(textField.getText());
                        textField.setText("");
                        textField.requestFocusInWindow();
              getContentPane().add(button, BorderLayout.SOUTH);
         public static void main(String[] args)
              JFrame frame = new DemoCode();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }If you can't create a simple demo then you don't understand your problem and if you don't understand your problem then how are we supposed to?
    custom field So you probably have a coding problem and we have no idea what your code looks like
    that accepts only decimal values and why are you not using JFormattedTextField?
    And this problem is not seen if i modify the custom field using any other key say like "Backspace".Again this problem doesn't make sense since the character should be removed from the text field before the OK button is pressed.

  • Backspace on 2610

    I have found out how to move the cursor backwards after typing a wrong character, but don't know how to get rid of the wrong character.

    I ready I cna fo to stty to change so that backspace .........You may want to type a little slower :)
    And the command for your reference is "stty erase [backspace]", with [backspace] being you pressing the backspace key :) So on screen it would look like "stty erase ^H".
    You can also put that command in your profile or your rc file. That way you won't have to retype it every time :)

  • 10.4.10: moving cursor with arrows in the password field of Login Window

    Since installing 10.4.10 update, I cannot correct the arbitrary character in the login window which I mistakenly entered. It was quite useful to correct the typo. Now arrow keys simply don't move the cursor. Weird, but this edit field allows only deleting the whole password with backspace key and entering it again from the start.
    I checked, to see if the issue is not unique to me, a few Intel iMacs and minis in office and my home Mac, and it can be replicated everywhere.
    Does anybody know, what was behind this "very smart" Apple developers' solution? They didn't even bother to mention this in release note.

    today, after I had switched off my Mac over night and started it this morning, the Help Search Field works as expected ... (but why didn't it after the installation yesterday/restart?)

  • Follow Up Feature on Bold not on BB Classic - would be great to have it

    Follow up feature with sync to Outlook is a critical business feature that made BOLD a fantastic choice. I recently moved from Samsung to BB Classic hoping to use the old BOLD keys with the FOLLOW UP feature which is not as good in other mobiles including Samsung. However I am disappointed to see that this feature is missing! I would strongly recommend that this be included. I was also one of the many who expressed disappintment when Z-10 and the rest was launched with the classic BB keys missing. I am glad that BB is back with CLASSIC based on such feedback from many die hard BB fans. However the follow up feature is as critical as the trackball and I urge BB team to fix this urgently !!

    greghcrash wrote:
    It Would be great to have keys on the onscreen keyboard.
    Such as a computer keyboard.
    With BACKSPACE, TAB WITH SETTINGS, DELETE, TYPE OF TYPE, BOLD TYPE, UNDERLINE ETC....
    I HAVE A KEYBOARD COVER AND IF I NEED TO USE CERTAIN KEYS I HAVE TO SWITCH TO MY KEYBOARD CASE AND THAT IS VERY INCONVENIENT.
    IT IS ALSO A TIME WASTER.
    When you installed iOS 8 did you read about the new features? Applications can create custom keyboards…
    http://www.imore.com/custom-keyboards-ios-8-explained
    You need to look for an app that has a custom keyboard with the features you require, I suggest you find one without CAPSLOCK
    greghcrash wrote:
    IT IS ALSO AGGRAVATING WHEN TYPING AND IT AUTOMATICALLY CHANGES THE WORDS THAT YOU WANT TO USE.
    THANK YOU FOR YOUR TIME
    Again you need to look at how to manage the device - these settings can be turned off already & you can edit the 'suggestions' too.
    Settings > General > Keyboards > turn Auto-Correction Off.
    Sadly you cannot disable autocorrect temporarily, so it's all or nothing.

  • Is it possible to make st more responsive?

    I like st - it's lean and mean and slow as hell e.g. when I use the cursor keys.
    OK, so the last one is hardly a virtue, but maybe we can teach st to behave more like urxvt, which is a faster, but more complex piece of software and uses more memory.
    I'm using st with tmux, because st doesn't have a built-in scrollback buffer. st is pretty slow when moving around with cursor (or hjkl) keys, deleting with backspace or even selecting some text with my mouse, but it may be because of my old hardware, font settings or something else. If you want some info, tell me what exactly should I post.
    st alone (w/o tmux) is just as slow. Yes, I know about the nice ways you can copy with tmux, move around with vim and bash+readline, but st still feels sluggish.
    I'm happy with dwm+urxvtd, but I wanted to try something different and tmux is so sweet. st has no built-in tabs support and I yes, I know about 'tabbed', but I want to be tabs-less for a while.
    Any st users out there?
    I'm too afraid to post on the suckless ML ;P

    I've changed acceleration method to the semi-legacy uxa and my st experience has magically improved.
    Setting 'xset r' to something more aggressive, like 'xset r rate 200 30' doesn't hurt either.

Maybe you are looking for