e741. setting the focus of a jtextfield component using a jlabel component.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 14 行

TXT
14
字号
This example associates a label with a text field using setLabelFor(). A mnemonic is set on the label. When the mnemonic keystroke is pressed, the text field will gain the focus. 
In the following example, when ALT-L is pressed, the text field gains the focus. 

    // Create text field
    JTextField textfield = new JTextField(25);
    
    // Create label and associate with text field
    JLabel label = new JLabel("Text Label");
    label.setDisplayedMnemonic(KeyEvent.VK_L);
    label.setLabelFor(textfield);

 Related Examples 

⌨️ 快捷键说明

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