⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 focus.html

📁 jsf、swing的官方指南
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><html>    <head>        <title>How to Use the Focus Subsystem (The Java&trade; Tutorials &gt;             Creating a GUI with JFC/Swing &gt; Using Other Swing Features)</title><style type="text/css">    .FigureCaption   {         margin-left: 1in;         margin-right: 1in;         font-family: sans-serif;         font-size: smaller;         text-align: justify;    }    #TopBar_bl {        background: url(../../images/java_bar_bl.gif) 0 100% no-repeat;        width: 100%;        height: 60px;    }    #TopBar_br {        background: url(../../images/java_bar_br.gif) 100% 100% no-repeat;        width: 100%;        height: 60px;    }    #TopBar_tl {        background: url(../../images/java_bar_tl.gif) 0 0 no-repeat;        width: 100%;        height: 60px;    }    #TopBar_tr {        background: url(../../images/java_bar_tr.gif) 100% 0 no-repeat;        width: 100%;        height: 60px;    }    #TopBar {        background: #35556B url(../../images/java_bar.gif);        margin: 10px 10px 0 10px;        height:60px;        min-width:700px;        color: white;        font-family: sans-serif;         font-weight: bold;    }    @media print {        #BreadCrumbs, #Download {            display: none;        }    }    #TopBar_right {        line-height: 14px;        float: right;        padding-top: 2px;        padding-right: 30px;        text-align: center;    }    @media print {        #TopBar_right {            display: none;        }    }    #TopBar_right a {        font-size: 12px;        margin: 3px;        padding: 0;    }    #TopBar a:visited, #TopBar a:link {        color: white;        text-decoration: none;    }    #TopBar a:hover, #TopBar a:active  {        background-color: white;        color: #35556B;    }    #BreadCrumbs {        padding: 4px 5px 0.5em 0;        font-family: sans-serif;         float: right;    }    #BreadCrumbs a {        color: blue;    }    #BreadCrumbs a:visited, #BreadCrumbs a:link {        text-decoration: none;    }    #BreadCrumbs a:hover, #BreadCrumbs a:active {        text-decoration: underline;    }    #PageTitle {        margin: 0 5px 0.5em 0;        color: #E76F00;        font-family: sans-serif;         font-weight: bold;        font-size: 20px;    }    .LeftBar_shown {        width: 13em;        float: left;        margin-left: 10px;        margin-top: 4px;        margin-bottom: 2em;    }    @media print {        .LeftBar_shown {            display: none;        }    }    .LeftBar_hidden {        display: none;    }    #Footer {        padding-top: 10px;        padding-left: 10px;        margin-right: 10px;    }    .NavBit  {        padding: 4px 5px 0.5em 0;        font-family: sans-serif;     }    @media print {        .NavBit {            display: none;        }    }    #TagNotes {        text-align: right;        font-size: smaller;        font-family: sans-serif;     }    @media print {        #TagNotes a:visited, #TagNotes a:link {            color: #35556B;            text-decoration: none;        }    }    #Contents a, .NavBit a, #TagNotes a {        color: blue    }    #TagNotes a:visited, #TagNotes a:link,    #Contents a:visited, #Contents a:link,    .NavBit a:visited, .NavBit a:link {        text-decoration: none;    }    #TagNotes a:hover, #TagNotes a:active,       #Contents a:hover, #Contents a:active,       .NavBit a:hover, .NavBit a:active {          text-decoration: underline;    }    #Contents {        float: left;        font-family: sans-serif;     }    @media print {        #Contents {            display: none;        }    }    @media screen {        div.PrintHeaders {            display: none;        }    }    .linkLESSON, .nolinkLESSON {        margin-left: 0.5em;        text-indent: -0.5em    }    .linkAHEAD, .nolinkAHEAD, .linkQUESTIONS, .nolinkQUESTIONS   {        margin-left: 1.5em;         text-indent: -0.5em    }    .linkBHEAD, .nolinkBHEAD   {        margin-left: 2.5em;        text-indent: -0.5em    }    .linkCHEAD, .nolinkCHEAD   {        margin-left: 3.5em;        text-indent: -0.5em    }    .nolinkLESSON, .nolinkAHEAD, .nolinkBHEAD, .nolinkCHEAD,    .nolinkQUESTIONS {        font-weight: bold;        color: #E76F00;    }    .MainFlow_indented {        margin-right: 10px;        margin-left: 15em;        margin-bottom: 2em;    }    .MainFlow_wide {        margin-right: 10px;        margin-left: 10px;        margin-bottom: 2em;    }    @media print {        .MainFlow_indented, .MainFlow_wide {            padding-top: 0;            margin-top: 10px;            margin-right: 10px;            margin-left: 0;        }    }    h3, h4, h5 {        color: #E76F00;        font-family: sans-serif;    }    #ToggleLeft {        display: none;    }    /t</style><script type="text/javascript">    function leftBar() {        var nameq = 'tutorial_showLeftBar='        var cookies = document.cookie.split(';');        for (var i = 0; i < cookies.length; i++) {            var cookieString = cookies[i];            while (cookieString.charAt(0) == ' ') {                cookieString = cookieString.substring(1, cookieString.length);            }            if (cookieString.indexOf(nameq) == 0) {                cookieValue =  cookieString.substring(nameq.length,                        cookieString.length);                return cookieValue == 'yes';            }        }        return true;    }    function showLeft(b) {        var contents = document.getElementById("LeftBar");        var main = document.getElementById("MainFlow");        var toggle = document.getElementById("ToggleLeft");        if (b) {            contents.className = "LeftBar_shown";            main.className = "MainFlow_indented";            toggle.innerHTML = "Hide the TOC";            document.cookie = 'tutorial_showLeftBar=yes; path=/';        } else {            contents.className = "LeftBar_hidden";            main.className = "MainFlow_wide";            toggle.innerHTML = "Show the TOC";            document.cookie = 'tutorial_showLeftBar=no; path=/';        }    }    function toggleLeft() {        showLeft(document.getElementById("LeftBar").className ==                "LeftBar_hidden");        document.getElementById("ToggleLeft").blur();    }    function load() {        showLeft(leftBar());        document.getElementById("ToggleLeft").style.display="inline";    }    </script>    </head><body onload="load()">    <div id=TopBar> <div id=TopBar_tr> <div id=TopBar_tl> <div id=TopBar_br> <div id=TopBar_bl>                         <div id=TopBar_right>                             <a target="_blank"                                href="http://java.sun.com/javase/6/download.jsp">Download                                the JDK</a>                            <br>                            <a href="../../search.html" target="_blank">Search the                                Tutorials</a>                            <br>                            <a href="javascript:toggleLeft()"                                id="ToggleLeft">Hide the TOC</a>                        </div>                    </div> </div> </div> </div> </div>    <div class=PrintHeaders>        <b>Trail:</b> Creating a GUI with JFC/Swing        <br><b>Lesson:</b> Using Other Swing Features    </div>    <div id=LeftBar class=LeftBar_shown>        <div id=Contents>            <div class="linkLESSON"><a href="index.html">Using Other Swing Features</a></div><div class="linkAHEAD"><a href="action.html">How to Use Actions</a></div><div class="linkAHEAD"><a href="timer.html">How to Use Swing Timers</a></div><div class="linkAHEAD"><a href="access.html">How to Support Assistive Technologies</a></div><div class="nolinkAHEAD">How to Use the Focus Subsystem</div><div class="linkAHEAD"><a href="keybinding.html">How to Use Key Bindings</a></div><div class="linkAHEAD"><a href="problems.html">Solving Common Problems Using Other Swing Features</a></div></div>    </div>    <div id=MainFlow class=MainFlow_indented>            <span id=BreadCrumbs>                <a href=../../index.html target=_top>Home Page</a>                &gt;                <a href=../index.html target=_top>Creating a GUI with JFC/Swing</a>                &gt;                <a href=index.html target=_top>Using Other Swing Features</a>            </span>            <div class=NavBit>                <a target=_top href=access.html>&laquo;&nbsp;Previous</a>&nbsp;&bull;&nbsp;<a target=_top href=../TOC.html>Trail</a>&nbsp;&bull;&nbsp;<a target=_top href=keybinding.html>Next&nbsp;&raquo;</a>            </div>            <div id=PageTitle>How to Use the Focus Subsystem</div>            <blockquote>Many components &#151; even those primarily operatedwith the mouse, such as buttons &#151; can be operatedwith the keyboard.For a key press to affect a component,the component must have the keyboard focus.<p>From the user's point of view,the component with the keyboard focus is generallyprominent &#151; with a dotted or black border, for example &#151; and the window containing the component is also more prominentthan other windows onscreen.These visual cues let the user knowto which component any typing will go.At most one component in the windowsystem can have the keyboard focus.<p>Exactly how a window gains the focusdepends on the windowing system.There is no foolproof way, across all platforms,to ensure that a window gains the focus.On some systems, such as Microsoft Windows,the frontmost window becomes the focused window;in these cases, the method <code>Window.toFront</code>moves the window to the front thereby giving itthe focus.However, on some systems, such as Solaris,some window managers choosethe focused window based on cursor position; inthese cases <code>Window.toFront</code> does notresult in the same behavior.<p>A component generally gains the focus by the user clicking it,tabbing between components, or otherwiseinteracting with a component.A component can also be given the focus programmatically,such as when its containing frame or dialog is made visible.This code snippet shows how to give a particular component the focus every time the window is activated:<blockquote><pre>//Make textField get the focus whenever frame is activated.frame.addWindowListener(new WindowAdapter() {    public void windowActivated(WindowEvent e) {        textField.requestFocusInWindow();    }});</pre></blockquote><p>If you want to ensure that a particular component gainsthe focus the first time window is activated, you cancall <code>requestFocusInWindow</code> on the componentafter the componenthas been realized, but before the frame is displayed.Here is some sample code showing how this can be done:<blockquote><pre>    <em>//...Where initialization occurs...</em>    JFrame frame = new JFrame("Test");    JPanel = new JPanel(new BorderLayout());    <em>//...Create a variety of components here...</em>    //Create the component that will have the initial focus.    JButton button = new JButton("I'm first");    panel.add(button);    frame.getContentPane().add(panel);  //Add it to the panel    frame.pack();  //Realize the components.    <b>//This button will have the initial focus.    button.requestFocusInWindow();</b>     frame.setVisible(true); //Display the window.</pre></blockquote><blockquote><hr><strong>Version note:</strong>&nbsp;This section describes the focus architectureimplemented in release 1.4.  Prior to 1.4,<code>JComponent</code> methods such as<code>setNextFocusableComponent</code>,<code>getNextFocusableComponent</code>,<code>requestDefaultFocus</code>, and<code>isManagingFocus</code> were used tomanage the keyboard focus. These methods are now deprecated.Another method, <code>requestFocus</code>, is discouragedbecause it tries to give the focus to the component's window,which is not always possible.  As of 1.4,you should instead use <code>requestFocusInWindow</code>which does not attempt to make the component's window focused and which returns a boolean value indicating whetherthe method succeeded.<hr></blockquote><p>The rest of this section covers the following topics:<ul><li><a href=#intro>Introduction to the Focus Subsystem</a><li><a href=#inputVerification>Validating Input</a>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -