-
Cursor controlling?
I am stuck in a simple problem.Please anyone help me.
I am giving a simple code.After run the code two JTextField appear in a JFrame.After writing something,pressing ENTER,the text will be displayed.
Code:
///NewClass.java
import javax.swing.*;
import java.awt.*;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import java.sql.*;
import java.util.*;
import javax.swing.text.*;
import java.awt.event.*;
import java.util.Calendar;
class getkeyboard{
JTextField a,b;
JFrame frm;
Container cnt;
public getkeyboard(){
frm=new JFrame("Keyboard");
cnt=frm.getContentPane();
frm.setLayout(null);
a=new JTextField();
b=new JTextField();
frm.add(a);
frm.add(b);
a.setBounds(20,20,100,30);
b.setBounds(20,70,100,30);
a.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
System.out.println(a.getText());
}}
);
b.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
System.out.println(b.getText());
}}
);
frm.setVisible(true);
frm.setSize(300,300);
}
}
public class NewClass{
public static void main(String ayu[]){
try{
getkeyboard adfdf=new getkeyboard();
}catch(Exception e){}
}
}
But, I am in a need of that when I press ENTER in a JTEXTFIELD,the cursur should go to the next JTextField [like pressing the TAB]
How to do that??
-
requestFocus() or requestFocusInWindow()
-
Solved
Junky,
thanks,it's working.