Results 1 to 1 of 1
Thread: can i use requestFocus
- 02-09-2011, 06:22 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 1
- Rep Power
- 0
can i use requestFocus
I am given an assignment but I am totally new to Java (i have been programming in C++ and Python for two years).
So we are doing GUI and basically we extended JFrame and added a couple fields.
Say we have a field named "Text 1" and "Text 2". When user press enter with the cursor in Text 1, move the focus to Text 2. I tried to add
But that doesn't work at all.Java Code:private JTextField textfield1() { textfield1 = new JTextField(); textfield1.setPreferredSize(new Dimension(200, 20)); textfield1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { textfield1text = textfield1.getText().trim(); textfield1.setText(textfield1text); System.out.println(textfield1text); textfield1.requestFocus(); } }); return textfield1;
I noticed that requestFocus is not recommended, and instead one should use requestFocusWindows. But I tried that too. Upon some readings it seems like I have to do keyboard action & listener??? But my teacher said it only requires 1 line....
ANy help is appreciated.Last edited by jwxie; 02-09-2011 at 06:26 AM.
Similar Threads
-
RequestFocus on DefaultTableModel Particular Cell
By yernikumar in forum AWT / SwingReplies: 1Last Post: 03-01-2009, 04:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks