Register Enter KeyboardAction to a TextField

hi,
I am registering enter keyboard action to a textfield as following which is not working
Action done = new KeysAction("done",this);
amountTextField.addActionListener(this);
amountTextField.registerKeyboardAction(done,KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),JComponent.WHEN_IN_FOCUSED_WINDOW);
class KeysAction extends AbstractAction
String ac;
public KeysAction(String name,Component comp)
     ac=name;
target = comp;
public void actionPerformed(ActionEvent evt)
     if (ac.compareToIgnoreCase("done")==0)
System.out.println("Enter Key Pressed in Amount Field ");
private Component target;
please help

This thread uses InputMap/ActionMap classes to add an Action to a KeyStroke:
http://forum.java.sun.com/thread.jsp?forum=57&thread=450711

Similar Messages

  • How to register "Enter" event  in sap xrpm

    all expert:
    how to register "Enter" event  in sap xrpm

    all expert:
    how to register "Enter" event  in sap xrpm

  • Using Enter key on the TextField

    How to complete filling of the text to a TextField after pressing key "Enter"?

    pressing enter causes any ActionListener objects to be notified. checkout the java tutorial to see how to do this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html
    (note this actually uses a JTextField but it's pretty much the same with TextField)
    jonesy (sun developer support)

  • Enter key in jato:textField crashes ViewBean

    I have a jato:textField in a very simple JSP/ViewBean which was migrated
    from NetDynamics with the iMT tool and then hand-modified to work under the
    JATO framework.
    If I click Enter in the textField, the page crashes with ServletException
    "The request was not handled by the specified handler". It doesn't give a
    line number. Using an IDE debugger (JBuilder) I see that a forwardTo()
    method has been invoked.
    Other pages don't react to the enter key like this. They beep the
    client. Exactly what I want. Where do I look for trouble?
    Ned Kellogg
    Harvard University Development Office
    124 Mt Auburn Street, 4th Floor
    Cambridge, MA 02138
    617-495-4164
    [Non-text portions of this message have been removed]

    Did you try searching the forum first before posting your questions?
    The following keywords, taken directly from your question would be a good place to start: "disable enter jtextarea".

  • Prevent User From Entering Characters In A TextField

    Does anyone know how to prevent certain kinds of letters or symbols from being entered into a textfield? Something that prevents the user from typing a minus sign or the letter Q.

    You can also use KeyListener. You can also search the forum as this question has been asked numerous times.

  • Re-register / Enter Unlock Code Every Time PS Album is Launched

    Hi there,
    I have a client with Adobe Photoshop Album Starter Edition 3.2 bringing up the registration screen each time it's launched. The registration has been completed several times, and each time he did receive his unlock code. If you put the unlock code in, it is accepted no problem. However, next time Album is launched, it comes back up with the registration screen. Thanks in advance for any suggestions!

    Andrea:
    I had the same problem, registering again every time I opened the program, even though the unlock code had been accepted before.
    I was going to uninstall it.
    I went to "Add or Remove Programs", clicked "Adobe Photoshop Album Starter Edition 3.2"(the first of two entries), clicked "Change/Remove", and in the box that appeared was a choice to remove or repair. OK, what have I got to lose, so I chose repair. I then started the program, installed my unlock code one more time, and have been free of the problem since.
    Hope this will work for you.
    John

  • To fix the length of a textfield for user to enter date

    hi,
    i need to display a textfield for user to enter the date in the format MM/DD/YY.With the slash in between present and fixed and the possibility of entering only 2 digit figures for the month,day n' year.I am using JTextField .how can i acheive that pls help.

    You must design you own document where you will manage the text that will be entered/displayed in your textfield
    here's a sample of the code I use to do this:
    import javax.swing.JTextField;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MaskedTextField extends JTextField
    private String initStr;
    public MaskedTextField (String mask, String initStr)
    super();
    setDocument(new MaskedDocument(initStr, mask, this));
    setText(initStr);
    this.initStr = initStr;
    this.addMouseListener(new java.awt.event.MouseAdapter()
    public void mouseClicked(MouseEvent m)
    this_mouseClicked(m);
    private void this_mouseClicked(MouseEvent m)
    if (getText().equals(initStr)) setCaretPosition(0);
    class MaskedDocument extends PlainDocument
    String mask;
    String initStr;
    JTextField tf;
    public MaskedDocument(String initStr, String mask,
    MaskedTextField container)
    this.mask = mask;
    this.initStr = initStr;
    tf = container;
    void replace(int offset, char ch, AttributeSet a)
    throws BadLocationException
    super.remove(offset,1);
    if (capitalised) super.insertString(offset,
    String.valueOf(ch).toUpperCase(),a);
    else super.insertString(offset, "" + ch, a);
    public void remove(int offs, int len) throws BadLocationException
    if (len==0)
    return;
    // Remove current contents
    super.remove(offs, len);
    // Replace the removed part by init string
    super.insertString(offs,initStr.substring(offs,offs+len),
    getAttributeContext().getEmptySet());
    tf.setCaretPosition(offs);
    public void insertString(int offset, String str, AttributeSet a)
    throws BadLocationException
    if ((offset==0) && str.equals(initStr))
    // Initialisation of text field
    super.insertString(offset,str,a);
    return;
    if (str.length()==0)
    super.insertString(offset,str,a);
    return;
    for (int i=0;i<str.length();i++)
    while ((offset+i) < mask.length())
    if (mask.charAt(offset+i)=='-')
    // Skip fixed parts
    offset++;
    else
    // Check if character is allowed according to mask
    if (str.charAt(i) != this.initStr.charAt(i))
    switch (mask.charAt(offset+i))
    case 'D': // Only digitis allowed
    if (!Character.isDigit(str.charAt(i)))
    return;
    break;
    case 'C': // Only alphabetic characters allowed
    if (!Character.isLetter(str.charAt(i)))
    return;
    break;
    case 'A': // Only letters or digits characters allowed
    if (!Character.isLetterOrDigit(str.charAt(i)))
    return;
    break;
    replace(offset+i, str.charAt(i),a);
    break;
    else
    i++;
    offset--;
    // Skip over "fixed" characters
    offset += str.length();
    while ((offset<mask.length()) && (mask.charAt(offset)=='-'))
    offset++;
    if (offset<mask.length())
    tf.setCaretPosition(offset);
    if (offset == mask.length()) tf.setCaretPosition(offset);
    Enjoy
    Bernie

  • Checking If TextField Has Been Entered

    Basic, I know. Sorry, but I can't work it out.
    I need to check if a user has entered text in a textfield, if the user has entered text then I'll use it. If they haven't, I'll ignore it.
    I've been looking through the API for an isNull or isEmpty method, but can't seem to find anything.
    Can anyone help

    How abouttextArea.getText();If you want to check text on the text area gaining/losing focus, try:textArea.addFocusListener(new FocusListener(){
         public void focusGained(FocusEvent event){
              System.out.println("Gained focus: text on entry is " + ((JTextArea)event.getComponent()).getText());
         public void focusLost(FocusEvent event){
              System.out.println("Lost focus: text on leaving is " + ((JTextArea)event.getComponent()).getText());
    textArea.addKeyListener(new KeyListener(){
         public void keyTyped(KeyEvent event){
              System.out.println("Typed: " + event.getKeyChar());
    });Hope this helps.
    Chris.

  • Entering numbers into textfield

    Hi,
    is there any way of entering numbers into a textfield whereby the user doesn't have to toggel the device inorder to produce said numbers- a bit like a calculator application; any suggestions welcome
    James

    Sure, it is very easy.
    Read about TextField Input Constraints.
    They are
    ANY
    EMAILADDR
    NUMERIC
    PHONENUMBER
    URL
    DECIMALYou need NUMERIC or DECIMAL.
    You can set them in two way
    1. public void setConstraints(int constraints)2. Pass to TextField constructor:
    TextField(String label, String text, int maxSize, int constraints)e.g.
    TextField myTextField = new TextField("myLabel", "myText", 32, TextField.NUMERIC)Read also about Input Modes. It can be also useful.

  • Enter/Return in Textfield or other widgets

    I have the problem that my Plugin crashes if i enter something in a textfield (TextEditBoxWidget) or Dropdownlist (DropDownListWidget) and press Enter to submit the form instead of using the Button. How can i avoid this? The Update Method of DialogObserver is not entered.

    Sorry i posted this in wrong category. Could you put it into
    Adobe Community > InDesign > InDesign SDK ?

  • Why am I having to re-enter my registration information each time I open the application?

    Hi All,
    I purchased Apeture with my Macbook three years ago and have just recently decided to utilize it. EVERY time I open the program I'm prompted to enter my registration information. I'm entering the info each time, but would love not to! (I registered the product in an attempt to make the dialog box go away to no avail.) Any ideas?

    First of all, are you using an administrator account, when you are entering the serial number? Aperture needs to write the information to the system library, not the user library. Try to log in from an admin account while entering the serial number. If that does not help,  you may have a corrupted "ProAppSystemID" file or Aperture cannot write to the System Library.
    First check, if you still have an old file "ProAppSystemID" in your System Library.
    Quit Aperture.
    Go to your MacintoshHD and open the folder "Library", then "Application Support", then "ProApps".
    Remove the File "ProAppsSystemID" to the Desktop, if it exist and restart Aperture.
    Reenter your serial number, hopefully for the last time.
    Sometimes Aperture writes this file to a temporary directory, when it cannot write to the Library. If the above does not work, look at the temporary directory /tmp
    Use the Finder's "Go" menu
         Go > Got to folder    and  enter /tmp into the textfield. If you see the file there, move it to its proper location.
    Check the permission on the folder "Library", then "Application Support", then "ProApps". You (as admin) need to have read/write access to all flders along the path.
    Regards
    Léonie

  • Unable to get the value from the textfield in valueChangeEvent

    Hi,
    I have created one custom textField by extending the CoreInputText. Now i have attched default ValueChangeListener to it. I am using this textField in my application.
    Now i type some thing and do a focus lost, the value change listener get called. i want to validate the value entered. In that listener method if i take the getSource() from ValueChnageEvent object and do a getValue() I am getting the entered value.
    My problem is that if i do a getValue() of the textField i am not gettting the value entered.
    How can i get the entered value from the textfield.? Is there any method to notify to do this?
    Thanks in advance.

    Hi,
    I tried to the value from coreInputText also. If i check the getValue method of the component, i am getting the last updated value. I have debug the FlowPhaseListsner also. And i found that this listener is calling before the updateModel phase. Due to that i am not getting the value from the Field.

  • Problem reading data from textField?

    I have a problem in my program I'm currently doing.
    I have a textArea and a textField in a container.
    Inside the textArea will be displayed some questions which require user to give answers to in the textField.
    When user types something in the textField and presses enter, an actionListener will trigger and take in String.
    My problem is how do you wait for the user to type something in the textField?
    thanks

    Hi
    I am trying to read a value from a textField object in the following code, but its returning an empty string. any kind of help would be appreciated. thanks.
    bhavesh
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.io.*;
    import java.lang.*;
    public class Applet1 extends Applet implements ActionListener, TextListener{
         String text = "";
         Image logo;
         static TextField usr;
         static TextField pswd;
         static Button logOn;
         public boolean authenticate(Graphics g){
              g.setColor(Color.RED);
              g.setFont(new Font("Monospaced", Font.PLAIN, 20));
              text = "Username:";
              g.drawString(text, 300, 300);
              text = "Password:";
              g.drawString(text, 300, 325);
              g.setFont(new Font("Serif", Font.PLAIN, 20));
              usr = new TextField(40);
              usr.setBounds(420,280, 200,20);
              usr.setEditable(true);
              //usr.addActionListener(this);
              add(usr);
              //add (new Label("Enter number:"));
              pswd = new TextField(40);
              pswd.setEditable(true);
              pswd.setBounds(420,310, 200,20);
              //pswd.addActionListener(this);
              add(pswd);
              //add (new Label("Enter number:"));
         logOn = new Button("Log on ...");
         logOn.setBounds(380,340,80,20);
              logOn.addActionListener(this);
              add(logOn);
              return true;
         public void actionPerformed(ActionEvent ae){
              System.out.print(usr.getText()+"rr\n"+ae);
              System.out.print(pswd.getText()+"bb\n");
              if ( usr.getText().compareTo("gusr")==0 && pswd.getText().compareTo("gpswd")==0 ){
                   System.out.print("COOOOOOL");
              else{
                   System.out.print("BAD");
         public void textValueChanged(TextEvent te){
              String foo = usr.getText();
              System.out.print("\n\nevent please\n\n"+foo+" +"+usr.getSelectedText());
         public void paint(Graphics g) {
              logo = getImage(getCodeBase(),"logo2.gif");
              g.setColor(Color.WHITE);
              g.fillRect(0,0,1000,625);
              g.drawImage(logo, 0, 0, this);
              g.setFont(new Font("SansSerif", Font.ITALIC, 20));
              g.setColor(Color.BLUE);
              text = "Welcome to AMPD Timecard!";
              g.drawString(text, 300, 255);
              authenticate(g);

  • HT3805 Aperture keeps asking me to register.  I register and it runs fine.  But then when I rerun Aperture, it asks for me to register again.

    This is a replacement serial number that I am typing in.  I got it from a technician and was told to use it rather than my old serial number.  I would appreciate some help on this.

    First of all, are you entering your serial number from an administrator account, or from a plain user account? If you enter the serial number as a regular user, Aperture cannot write the registration to the system library, and you will have to enter it again, when you log in again.
    Also, you may have a corrupted "ProAppSystemID" file or Aperture cannot write to the System Library.
    To stop Aperture asking for the serial number, first check, if you still have an old file "ProAppSystemID" in your System Library.
    Quit Aperture.
    Go to your MacintoshHD and open the folder "Library", then "Application Support", then "ProApps".
    Remove the File "ProAppsSystemID" to the Desktop, if it exist and restart Aperture.
    Reenter your serial number, hopefully for the last time.
    Sometimes Aperture writes this file to a temporary directory, when it cannot write to the Library. If the above does not work, look at the temporary directory /tmp
    Use the Finder's "Go" menu
         Go > Got to folder    and  enter /tmp into the textfield. If you see the file there, move it to its proper location.
    Regards
    Léonie

  • Unable to register URL services

    I am not able to register URL Sample Services
    JPDK 3.0.9 Portal 3.0.9.8.1
    jserv.log
    [23/10/2001 15:39:19:154 CEST] urlsample/Entering init
    [23/10/2001 15:39:19:154 CEST] urlsample/Debug Level is : 5
    [23/10/2001 15:39:19:154 CEST] urlsample/Added debuglevel to
    session storage.
    [23/10/2001 15:39:19:184 CEST] urlsample/register : Entering
    register() method ...
    [23/10/2001 15:39:19:184 CEST] urlsample/register : No
    subscriberDetails tag found. Continuing ...
    [23/10/2001 15:39:19:194 CEST] urlsample/Action = 1
    [23/10/2001 15:39:19:194 CEST]
    urlsample/java.lang.IllegalStateException: User not passed in
    request.
         at
    oracle.portal.provider.v1.http.ServletProviderRequest.getProvider
    User(ServletProviderRequest.java:237)
         at oracle.portal.provider.v1.http.HttpProvider.service
    (HttpProvider.java, Compiled Code)
         at javax.servlet.http.HttpServlet.service
    (HttpServlet.java:588)
         at org.apache.jserv.JServConnection.processRequest
    (JServConnection.java:435)
         at org.apache.jserv.JServConnection.run
    (JServConnection.java:290)
         at java.lang.Thread.run(Thread.java:479)
    [23/10/2001 15:39:19:435 CEST] urlsample/Traverse WebDB request
    tree:

    Quick question
    Check correctness of provider.xml, by typing
    http://myserver.mydomain.com:port/servlets/<provider_name> in web
    browser. (After modifying jserv.properties and zone.properties )
    This should display Test Page with provider_name.
    The same download is working fine for me.

Maybe you are looking for