Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java - JScrollPane - stop scrolling with up/down arrows?

Options
  • 04-04-2007 10:38am
    #1
    Registered Users Posts: 839 ✭✭✭


    Hi folks,

    I have a JScrollPane with a large JPanel in it, that JPanel has a number of smaller JPanels inside it (each represents a row of data in a table). Inside each panel is a number of JTextFields, JComboBoxes and JButtons. Basically, if one of the JTextFields or JButtons has focus and I press the up or down arrow keys (on the keyboard), the whole scroll pane moves up or down. Yet it doesn't seem to happen with JComboBoxes (or JTextAreas) when they have the focus and I press up or down arrows.

    Question: How can I get the scroll pane to stop automatically moving when up and down arrows are pressed?

    Thanks,
    Brian

    PS - I don't like JTable before somebody suggests that! I find it dodgy/unreliable


Comments

  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    Use a JTable.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    He already said he didn't want to use a JTable. If you're going to suggest something like that then at least explain the advantages of it to the OP.

    Future unhelpful posts like that will result in a banning.


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    Hehe, sorry Evil Phil, he's sitting right beside me so it was meant as a joke, obviously quite difficult for you to ascertain that through the interweb :)


  • Registered Users Posts: 839 ✭✭✭Dr Pepper


    Just in case anyone is ever looking for this, I've found the solution here:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=632514

    It's the first reply by the user called 'data-loss'. I've just put this line at the start of my constructor and it worked perfectly (no more annoying automatic key actions on JScrollPanes):
    UIManager.getDefaults().put("ScrollPane.ancestorInputMap", 
    new UIDefaults.LazyInputMap(new Object[] {}));
    

    He also suggests a method of supressing specific keys actions on specific JScrollPanes but I'm happy enough with getting rid of them all for my purposes.

    Ahhhh.. There goes another half day spent being anal about my user interfaces :o


Advertisement