Hi, I wrote the following code to create hotkeys in java Swing. I am creating Mnemonic for Jtextfield1 (Name) . He showed it correctly, but now I need to know that when I start, I immediately press tf2 , then the cursor will take the value tf2 from tf1 .
I enter some values ββin tf2 . Then I need to enter tf1 . In this situation, I press ALT+N (because N is mnemonic tf1 ). The cursor focused tf1 and entered the name in the text box. how to do it?
package hotkeys; import java.awt.event.*; import javax.swing.*; import java.net.*; public class hotkey extends JFrame { public static void main(String arg[]) { JLabel Name=new JLabel("Name"); JTextField tf1=new JTextField(20); Name.setLabelFor( Name ); Name.setDisplayedMnemonic( 'N' ); JLabel Regno=new JLabel("Reg_NO"); JTextField tf2=new JTextField(20); JButton b1=new JButton("Save"); JButton b2=new JButton("eXit"); JFrame f=new JFrame(); JPanel p=new JPanel(); p.add(Name); p.add(Regno); p.add(tf1); p.add(tf2); p.add(b1); p.add(b2); f.add(p); f.setVisible(true); f.pack(); } }
source share