📄 focus.html
字号:
<td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#setFocusable(boolean)">setFocusable(boolean)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#isFocusable()">isFocusable()</a></td><td>Set or get the focusable state of the component.A component must be focusable in order to gain the focus.When a component has been removed from the focus cycle with<code>setFocusable(false)</code>, it can no longer be navigatedwith the keyboard. We prefer <code>setRequestFocusEnabled</code>so that your program can be run by users employing<a href=access.html>assistive technologies</a>.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Component.html#requestFocusInWindow()">requestFocusInWindow()</a></td><td>Request that this component gets the focus. The component's window must be the current focused window. A subclass of <code>JComponent</code> must be visible, enabled, and focusable, and have an input map for this request to be granted. Even so, it shouldn't be assumed that the component has focus until it fires a <code>FOCUS_GAINED</code> event. This method is preferred to <code>requestFocus</code>, which is platform dependent.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Container.html#setFocusTraversalKeys(int, java.util.Set)">setFocusTraversalKeys(int, Set)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Container.html#getFocusTraversalKeys(int)">getFocusTraversalKeys(int)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Container.html#areFocusTraversalKeysSet(int)">areFocusTraversalKeysSet(int)</a><br>(<em>in <code>java.awt.Container</code></em>)</td><td>Set or get the focus traversal keys for a particulardirection or determine whether any focus traversal keys havebeen explicitly set on this container. If no focus traversalkeys have been set, they are inherited from an ancestor orfrom the keyboard focus manager. Focus traversal keyscan be set for the following directions: <code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code>,<code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code><code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code>, or<code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code>.If you set the <code>UP_CYCLE_TRAVERSAL_KEYS</code> or the<code>DOWN_CYCLE_TRAVERSAL_KEYS</code>, you must also invoke <a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/SortingFocusTraversalPolicy.html#setImplicitDownCycleTraversal(boolean)"><code>setImplicitDownCycleTraversal(false)</code></a> on the focus traversal policy.</td></tr></table><p align=center><a name="focustraversal">Creating and Using a Custom FocusTraversalPolicy</a><p><em>All of this API was introduced in release 1.4. Unless otherwise specified, each method is defined in the <code>FocusTraversalPolicy</code> interface.</em><table border=1><tr><th align=left>Class or Method</th><th align=left>Purpose</th></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/LayoutFocusTraversalPolicy.html">LayoutFocusTraversalPolicy</a></td><td>The class that, by default, determines the focus traversal policy for Swing components.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/LayoutFocusTraversalPolicy.html#getComponentAfter(java.awt.Container, java.awt.Component)">getComponentAfter(Container, Component)</a></td><td>Given the component passed in, return the component that should next have the focus.</td></tr> <tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/LayoutFocusTraversalPolicy.html#getComponentBefore(java.awt.Container, java.awt.Component)">getComponentBefore(Container, Component)</a></td><td>Given the component passed in, return the component that should have the focus before this one. This is used for backwards tabbing.</td></tr> <tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/SortingFocusTraversalPolicy.html#getDefaultComponent(java.awt.Container)">getDefaultComponent(Container)</a><br>(<em>in <code>javax.swing.SortingFocusTraversalPolicy</code>)</em></td><td>Return the component that should have the default focus.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/LayoutFocusTraversalPolicy.html#getFirstComponent(java.awt.Container)">getFirstComponent(Container)</a></td><td>Return the first component in the traversal cycle.</td></tr> <tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/InternalFrameFocusTraversalPolicy.html#getInitialComponent(java.awt.Container)">getInitialComponent(Container)</a></td><td>Return the component that should receive the focus when a window is made visible for the first time.</td></tr> <tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/LayoutFocusTraversalPolicy.html#getLastComponent(java.awt.Container)">getLastComponent(Container)</a></td><td>Return the last component in the traversal cycle.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Container.html#setFocusTraversalPolicy(java.awt.FocusTraversalPolicy)">setFocusTraversalPolicy(FocusTraversalPolicy)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Container.html#getFocusTraversalPolicy()">getFocusTraversalPolicy(FocusTraversalPolicy)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/Container.html#isFocusTraversalPolicySet()">isFocusTraversalPolicySet()</a><br>(<em>in <code>java.awt.Container</code></em>)</td><td>Set or get the focus traversal policy or determine if one has been set. Note that setting a focus traversal policy on a container that is not the focus cycle root may have no apparent effect. A value of <code>null</code> means that a policy has not been explicitly set. If no policy has been set one is inherited from the parent focus cycle root.</td></tr></table><p align=center><a name="inputverificationapi">Input Verification API</a><p><em>All of this API was introduced in release 1.3.</em><table border=1><tr><th align=left>Class or Method</th><th align=left>Purpose</th></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/InputVerifier.html">InputVerifier</a></td><td>Abstract class that allows input validation via the focus mechanism. When an attempt is made to shift the focus from a component containing an input verifier, the focus is not relinquished until the verifier is satisfied.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/InputVerifier.html#shouldYieldFocus(javax.swing.JComponent)">shouldYieldFocus(JComponent)</a><br><em>(in <code>InputVerifier</code>)</em></td><td>When a component has an input verifier, this method is called by the system to determine whether the focus can leave this component. This method may cause side effects, such as bringing up a dialog. If this method returns false, the focus remains on the component passed in to the method.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/InputVerifier.html#verify(javax.swing.JComponent)">verify(JComponent)</a><br><em>(in <code>InputVerifier</code>)</em></td><td>You need to override this method to check that the component's input is valid. It should return true if valid, otherwise return false. This method should not cause any side effects, such as bringing up a dialog. This method is called by <code>shouldYieldFocus</code>.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#setInputVerifier(javax.swing.InputVerifier)">setInputVerifier(inputVerifier)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#getInputVerifier()">getInputVerifier()</a><br><em>(in <code>JComponent</code>)</em></td><td>Set or get the input verifier assigned to the component. By default, components have no inputverifier.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#setVerifyInputWhenFocusTarget(boolean)">setVerifyInputWhenFocusTarget(boolean)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#getVerifyInputWhenFocusTarget()">getVerifyInputWhenFocusTarget()</a><br><em>(in <code>JComponent</code>)</em></td><td>Set or get whether the input verifier for the current focus owner is called before this component requests the focus. The default is true. This should be set to false for components, such as a Cancel button or a scroll bar, that should receive the focus even if input is invalid.</td></tr></table><p align=center><a name="properties">KeyboardFocusManager Properties</a><p>This table defines the bound properties for<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/KeyboardFocusManager.html"><code>KeyboardFocusManager</code></a>. A listener can be registered for these properties by calling<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/KeyboardFocusManager.html#addPropertyChangeListener(java.beans.PropertyChangeListener)"><code>addPropertyChangeListener</code></a>.<p><em>All of this API was introduced in release 1.4.</em><table border=1><tr><th align=left>Property</th><th align=left>Purpose</th></tr><tr><td>focusOwner</td><td>The component that currently receiveskey events.</td></tr><tr><td>permanentFocusOwner</td><td>The component that most recently received apermanent <code>FOCUS_GAINED</code> event.Typically the same as <code>focusOwner</code>, unlessa temporary focus change is currently in effect. </td></tr><tr><td>focusedWindow</td><td>The window that is or that contains the focus owner.</td></tr><tr><td>activeWindow</td><td>Must always be either a <code>Frame</code> or a<code>Dialog</code>. The active window is either thefocused window, or the first frame or dialog that is anowner of the focused window.</td></tr><tr><td>defaultFocusTraversalPolicy</td><td>The default focus traversal policy. This can beset by the <code>Container</code><code>setFocusTraversalPolicy</code> method.</td></tr><tr><td>forwardDefaultFocusTraversalKeys</td><td>The set of default focus keys for a forward traversal.For multi-line text components, this defaults to Control-Tab. For all other components, this defaults to Taband Control-Tab.</td></tr><tr><td>backwardDefaultFocusTraversalKeys</td><td>The set of default focus keys for a backwards traversal.For multi-line text components this defaults to Control-Shift-Tab.For all other components this defaults to Shift-Taband Control-Shift-Tab.</td></tr><tr><td>upCycleDefaultFocusTraversalKeys</td><td>The set of default focus keys for an up cycle. These are null, by default, for Swing components. If you set these keys on the <code>KeyboardFocusManager</code>, or if you set the <code>downCycleFocusTraversalKeys</code> on a focus cycle root, you must also invoke<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/SortingFocusTraversalPolicy.html#setImplicitDownCycleTraversal(boolean)"><code>setImplicitDownCycleTraversal(false)</code></a> on the focus traversal policy.</td></tr><tr><td>downCycleDefaultFocusTraversalKeys</td><td>The set of default focus keys for a down cycle. These are null, by default, for Swing components. If you set these keys on the <code>KeyboardFocusManager</code>, or if you set the <code>upCycleFocusTraversalKeys</code> on a focus cycle root, you must also invoke<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/SortingFocusTraversalPolicy.html#setImplicitDownCycleTraversal(boolean)"><code>setImplicitDownCycleTraversal(false)</code></a> on the focus traversal policy.</td></tr><tr><td>currentFocusCycleRoot</td><td>The container that is the current focus cycle root.</td></tr></tr></table></blockquote><h3><a name="eg">Examples that Use Focus</a></h3><blockquote>The following table lists examples thatmanipulate the focus:<p><table><tr valign = top><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes</th></tr><tr valign = top><td> <a href="examples/index.html#FocusConceptsDemo"> <code>FocusConceptsDemo</code></a></td><td> This section</td><td> Demonstrates basic default focus behavior.</td></tr><tr valign = top><td> <a href="examples/index.html#FocusTraversalDemo"> <code>FocusTraversalDemo</code></a></td><td> This section</td><td> Demonstrates how to override the default focus order.</td></tr><tr valign = top><td> <a href="examples/index.html#TrackFocusDemo"> <code>TrackFocusDemo</code></a></td><td> This section</td><td> Demonstrates how to use a <code>PropertyChangeListener</code> to track the focus owner. Also implements a custom focusable component.</td></tr><tr valign = top><td> <a href="examples/index.html#InputVerificationDemo"> <code>InputVerificationDemo</code></a></td><td> This section</td><td> Demonstrates how to implement an <code>InputVerifier</code> to validate user input.</td></tr><tr valign = top><td> <a href="examples/index.html#InputVerificationDialogDemo"> <code>InputVerificationDialogDemo</code></a></td><td> This section</td><td> Demonstrates how to implement an <code>InputVerifier</code> that puts up a dialog when user input is invalid.</td></tr><tr valign = top><td><a class="TutorialLink" target="_top" href="../events/examples/index.html#FocusEventDemo">FocusEventDemo</a><td><a class="TutorialLink" target="_top" href="../events/focuslistener.html">How to Write a Focus Listener</a></td><td> Reports all focus events that occur on several components to demonstrate the circumstances under which focus events are fired.</td></tr></table> </blockquote> <div class=NavBit> <a target=_top href=access.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=keybinding.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> How to Support Assistive Technologies <br><b>Next page:</b> How to Use Key Bindings </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -