Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:31:01+00:00 2026-06-11T15:31:01+00:00

OK here we go again. Steve has to program another non-standard set of key

  • 0

OK here we go again. Steve has to program another non-standard set of key strokes.
We have an editable JTextPane embedded in a JScrollPane. This pane correctly handles the Up and Down arrow keys, but I can’t figure out how. If I could figure out how, I could implement the nonstandard things I need to implement.

Specifically, because the PageDown key is globally mapped to doing another function we don’t do the default actions for PageUp, PageDown,Ctrl-PageUp and Ctrl-PageDown. Instead we want to map these functions to the shifted arrow keys, not the ones on the numeric keypad.

Specifically in the JScrollPane class’s ancestor input map ((InputMap)UIManager.get(“ScrollPane.ancestorInputMap”);) we add the

  • Shifted Down Arrow key to the Ancestor input map pointing to
    the”scrollDown” action
  • Shifted Up Arrow key to the Ancestor input map pointing to the
    “scrollUp” action
  • Shifted Left Arrow key to the Ancestor input map pointing to the
    “scrollHome” action
  • Shifted Right Arrow key to the Ancestor input map pointing to the
    “scrollEnd” action

None of these keystrokes do anything. I’vwe even overridden the processKeyEvent() and processKeyBinding() methods of JComponent to log what was going on, and I find that these methods are never fired by these keystrokes. Also, the plain standard up arrow and down arrow keystrokes do not fire these methods, even though these keystrokes do work.

So it seems clear that something else is handling these keystrokes. But what component is that?
And yes, the text pane does have focus when I am trying this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:31:02+00:00Added an answer on June 11, 2026 at 3:31 pm

    OK, trashgod was basically right. The solution was to use the KeyBindings names for the action. The delay in finding the right answer was due to a stray bit of code that was undoing the mapping elsewhere.

    More specifically, we disable the default keystrokes in the JTextPane and then add them to the input map of the Scroll Pane, mapped to their new actions.

    In the TextPane constructor

    ...
            disableAction("caret-down"); // down arrow
            disableAction("caret-up");   // up arrow
            disableAction("selection-backward"); // shift-left-arrow
            disableAction("selection-forward");  // shift-right-arrow
            disableAction("selection-up");  //shift-up-arrow
            disableAction("selection-down"); // shift-down-arrow
    
        }
    
        private void disableAction(String name) {
            Action a = getActionMap().get(name);
            if (a != null) {
                a.setEnabled(false);
            }
        }
    

    In the ScrollPane

    import static javax.swing.KeyStroke.getKeyStroke;
    import static java.awt.event.KeyEvent.*;
    ...
        private void remapShiftedArrowKeys() {
            InputMap map = (InputMap)UIManager.get("ScrollPane.ancestorInputMap");
            map.put(getKeyStroke(VK_DOWN, SHIFT_DOWN_MASK), "scrollDown");
            map.put(getKeyStroke(VK_UP, SHIFT_DOWN_MASK), "scrollUp");
            map.put(getKeyStroke(VK_LEFT, SHIFT_DOWN_MASK), "scrollHome");
            map.put(getKeyStroke(VK_RIGHT, SHIFT_DOWN_MASK), "scrollEnd");
        }
    

    note that we don’t have to map shifted Up and Down keys because the JScrollPane already does what we want with those keys. It is simply enough to unmap them from the JTextPane. Whereas these other four keystrokes are completely non-standard and must also be remapped in the Scroll Pane.

    Thanks for all your help!

    Oh, and the actual answer is that the JTextPane normally handles those arrow keys of course. To do what I wanted I had to defeat that and map appropriately in the scroll Pane,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I seem to ask hard questions but here I go again. I have
I followed this guide here perfectly and have gone through it again but when
Hello again everyone, This time I have a problem with Intent & Extras. here's
ok, I'm here again to ask one dummy question. I have a custom dialog
I do not have any other option, but to ask here again... and problem
MVC newbie here again! I have two lists in my controller. IList<Cars> allCars =
I'm here again with another question/problem. I know that topic's title may be like
I'm stuck here again. I have a database with over 120 000 coordinates that
Scorliss here again. As a client has recently asked me to add multiple image
Rookie C++ Programmer here again I'm using VC++ VS2008 and making an attempt at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.