DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: disabling ENTER key

  1. #1
    Join Date
    Mar 2004
    Posts
    4

    disabling ENTER key

    Hi guys,

    How can I disable ENTER key so that when a user presses enter in my swing application it does nothing?

    thanks,
    Alex

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    well what is it that pressing enter in your application actually does?? you could write an action listener that listens for the enter key, and if it's pressed it sets a flag that stops anything happening etc

  3. #3
    Join Date
    Mar 2004
    Posts
    4
    I have this KeyListener:
    PHP Code:
    private class KListener implements KeyListener {
           public 
    void keyPressed(KeyEvent ke){
                      
    int key ke.getKeyCode();
                      if (
    key == KeyEvent.VK_ENTER)
                          
    System.out.println("ENTER");
           }
            public 
    void keyTyped(KeyEvent ke){}
            public 
    void keyReleased(KeyEvent ke){}

    I attach it to the all buttons in my app. May be I should attach it to the whole application in init()?
    Also,
    you could write an action listener that listens for the enter key, and if it's pressed it sets a flag that stops anything happening etc
    How do I do that?

    thanks,
    webtekie

  4. #4
    Join Date
    Feb 2004
    Posts
    541
    well you just test for which key has been pressed. If the key is the enter key then you do nothing, if it is some other key then you perform the relevant action.

  5. #5
    Join Date
    Feb 2004
    Posts
    808
    please note that events are sent to registered listeners in sequence.. if you wish to cancel the event so that it is not processed by anyone else, you should consume() it

    the specified key listener needs attaching to anything that might respond to an enter key.. as this is most of the components in the program, youre going to have a lot of attaching to do
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  6. #6
    Join Date
    Mar 2004
    Posts
    4
    thanks guys. Will try implementing this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center