1. 程式人生 > >e741. 將標簽的焦點置於關聯的文本框上面

e741. 將標簽的焦點置於關聯的文本框上面

nic span pre 文本框 焦點 tdi amp spl related

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

e741. 將標簽的焦點置於關聯的文本框上面