|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.event.KeyAdapter
com.bric.plaf.FocusArrowListener
public class FocusArrowListener
This listens for arrow keys and shifts the keyboard focus accordingly. So if you press the left arrow key, the component to the left of the source component requests the focus.
This scans for the first available component whose
isFocusable()
method returns true
.
If no such component is found: nothing happens.
Constructor Summary | |
---|---|
FocusArrowListener()
|
Method Summary | |
---|---|
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. |
Methods inherited from class java.awt.event.KeyAdapter |
---|
keyReleased, keyTyped |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FocusArrowListener()
Method Detail |
---|
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |