Java Reference
In-Depth Information
frame.setSize(300, 200);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
Figure 2-11 shows the main window of the program.
Figure 2-11. Focus management example
Examining Focus Cycles
One customization option available at the Swing container level is the focus cycle. Remember
that the focus cycle for a container is a map of the focus traversal order for the closed set of
components. You can limit the focus cycle to stay within the bounds of a container by setting
the focusCycleRoot property to be true , thus restricting the focus traversal from going beyond
an inner container. Then, when the Tab key is pressed within the last component of the container,
the focus cycle will wrap back to the first component in the container, instead of moving the
input focus to the first component outside the container. When Shift-Tab is pressed in the first
component, it wraps to the last component of the container, instead of to the prior component
in the outer container.
Figure 2-12 illustrates how the focus ordering would look if you placed the middle three
buttons from Figure 2-10 within a container restricted in this way. In this cycle, you cannot get
to the first component on the third row by pressing the Tab key to move forward. To be able to
tab into the second row container, you need to set the focusTraversalPolicyProvider property
to true . Otherwise, while the panel will keep the traversal policy within the second row, tabbing will
never get you into the third row.
 
Search WWH ::




Custom Search