public class FocusArrowListener extends KeyAdapter
This scans for the first available component whose
isFocusable()
method returns true
.
If no such component is found: nothing happens.
Constructor and Description |
---|
FocusArrowListener() |
Modifier and Type | Method and Description |
---|---|
static Set |
getFocusableComponents(Component currentFocusOwner)
Returns a set of all the components that
can have the keyboard focus.
|
void |
keyPressed(KeyEvent e) |
static boolean |
shiftFocus(int dx,
int dy,
Component src)
Shifts the focus in a certain direction.
|
keyReleased, keyTyped
public void keyPressed(KeyEvent e)
keyPressed
in interface KeyListener
keyPressed
in class KeyAdapter
public static boolean shiftFocus(int dx, int dy, Component src)
dx
- the amount to increment x.dy
- the amount to increment y.src
- the source to traverse from.public static Set getFocusableComponents(Component currentFocusOwner)
My first implementation involved of this concept
simply involved asking JCompnonents if they were
focusable, but in the FilledButtonTest
this
resulted in shifting focus to the ContentPane. Although
it is technically focusable: if I used the tab key
I did not get this result. So I studied
the inner workings for Component.transferFocus()
and ended up with a method that involved
calls to getFocusCycleRootAncestor()
,
and getFocusTraversalPolicy()
.
(Also credit goes to Werner for originally tipping me off towards looking at FocusTraversalPolicies.)
currentFocusOwner
- the current focus owner.