I've been looking for a solution for this, I think, very common, problem, with Java Swing, but can't find specific answers.
I have this Swing JPanel
with a scrollable JPanel
on top, showing an image of a document.
Below there is more Swing components, e.g. a JTable
and some textboxes, JButton
controls etc. in another panel. (There are more panels in the same JWindow
.)
When user edits data etc. in the boxes below, these of course gains focus as it should be. Now when the user wants to scroll for some specific data in the document, he/she needs to set focus (with mouse/tab) on this first, and then scroll.
So user would like to use e.g. arrow up/down keyboard without leaving focus from the other component he is working with.
I've tried to set keyboard handlers up, but can not get it to work without involving moving focus to the top.
Isn't there a way to scroll a scrollable Swing component without this component (and another) has focus?
If the components are text fields in the scroll pane, it seems Page Down works if the (first, at least) text field is focused. This is the result of running such code and hitting Page Down a few times.
If this behavior is needed while components outside the scroll pane are focused, perhaps look to key bindings.