Set focus to a text field
publicvoid addEmployees (int id,int sort,int roster)
{
String name =null;
String position =null;
switch (roster)
{
case 1:
name = addName1.getText ();
position = (String) addPosition1.getSelectedItem ();
break;
case 2:
name = addName2.getText ();
position = (String) addPosition2.getSelectedItem ();
break;
}
al.add ("INSERT INTO employees (manager, name, position, sort) VALUES (" + id +", '" + name +"', '" + position +"', '" + sort +"')");
switch (roster)
{
case 1:
employeeAddRemoveLabel1.setText (name +" has been added to the roster.");
addName1.setText("");
addName1.requestFocus ();
employeeAddRemoveLabel1.setForeground (Color.BLUE);
break;
case 2:
employeeAddRemoveLabel2.setText (name +" has been added to the roster.");
addName2.setText("");
addName2.requestFocus ();
employeeAddRemoveLabel2.setForeground (Color.BLUE);
break;
}
System.out.println (al +"\n");
System.out.println ("The size of the array list is " + al.size ());
updateEmployees (roster,name,true);
}
I haveaddName*.requestFocus (); so why isn't that JTextField being focused when the method is called? Basically the user clicks a JButton that calls the above method to add a user that was entered in a JTextField. It's supposed to then clear the JTextField and set focus to it so you can type in another user without having to click on the text field to give it focus again.

