Java tutorial
import java.awt.BorderLayout; import java.awt.event.KeyEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; public class Main { public static void main(String args[]) { JFrame frame = new JFrame("Label Focus Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField); frame.add(label, BorderLayout.WEST); frame.add(textField, BorderLayout.CENTER); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 100); frame.setVisible(true); } }