Results 1 to 5 of 5
Like Tree2Likes
  • 2 Post By wsaryada

Thread: JScrollPane keyevents

  1. #1
    Alkor is offline Member
    Join Date
    Feb 2012
    Posts
    39
    Rep Power
    0

    Default JScrollPane keyevents

    Basic question, how would I disable the key events for JScrollPane like up,down,page up,page down etc.

    Thanks!

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: JScrollPane keyevents

    I would consume the key event if I don't want it to bubble up. Let say if I have a JTextArea and I add it into a container like JScrollPane. I will have some thing like the following key listener in my JTextArea.

    Java Code:
    ...
    if (e.getKeyCode() == KeyEvent.VK_UP) {
        e.consume();
    }
    ...

  3. #3
    Alkor is offline Member
    Join Date
    Feb 2012
    Posts
    39
    Rep Power
    0

    Default Re: JScrollPane keyevents

    Ok, thanks im sure it will work, but hoping there was a simple way.

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: JScrollPane keyevents

    You could also use an InputMap of the component to disable some keys.

    Java Code:
    InputMap map = textArea.getInputMap();
    map.put(KeyStroke.getKeyStroke("UP"), "none");
    Fubarable and DarrylBurke like this.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: JScrollPane keyevents

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. JFrames and KeyEvents
    By CuddlyKittens11 in forum AWT / Swing
    Replies: 1
    Last Post: 05-05-2011, 12:58 AM
  2. Question on Graphics/JFrame/KeyEvents
    By loopsnhoops in forum New To Java
    Replies: 4
    Last Post: 02-10-2011, 11:22 PM
  3. Replies: 3
    Last Post: 02-02-2011, 10:53 AM
  4. Automatic convert to uppercase in keyevents
    By ashin in forum SWT / JFace
    Replies: 4
    Last Post: 08-09-2010, 01:59 PM
  5. Question about java keyevents?
    By Godsent in forum AWT / Swing
    Replies: 2
    Last Post: 10-26-2009, 09:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •