KeyEvent


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: KeyEvent

  1. #1
    Join Date
    Nov 2005
    Posts
    24

    KeyEvent

    if i require keys to activate buttons and methods etc without using the mouse, do i need a keyboard focus? isnt is as easy as just saying...


    public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_DOWN) {

    adjustLayout();
    }

    Obviously not cos its not working lol! any help guys?

  2. #2
    Join Date
    Aug 2003
    Posts
    313
    Make sure that you are adding the KeyListener to the component that will have the focus.
    Code:
    JPanel pnl = new JPanel();
    pnl.addKeyListener(new KeyListener() {
      public void keyPressed(KeyEvent e) {
        // ...
      }
      public void keyReleased(KeyEvent e) {
        // ...
      }
      public void keyTyped(KeyEvent e) {
        // ...
      }
    });
    Hope this helps.
    ~evlich

Similar Threads

  1. Replies: 0
    Last Post: 07-07-2000, 08:28 AM

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