it does work.. the only thing i did with your source code was put a semicolon on the end of the line with requestFocus().. it was missing, so maybe it didnt compile and you didnt notice...
here, as proof, try this simple code i knocked up:
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class testreplyfocus extends JApplet implements ActionListener
{
int whoGets=0;
JLabel prompt = new JLabel ("Test Request Focus");
JButton but = new JButton("Button");
JTextField text[] = new JTextField[5];
FlowLayout flow = new FlowLayout();
public void init()
{
Container con = getContentPane();
con.add(prompt);
con.add(but);
for(int i=0; i<text.length; i++){
text[i]=new JTextField("",10);
con.add(text[i]);
}
con.setLayout(flow);
but.addActionListener(this);
text[0].requestFocus();
}
public void actionPerformed(ActionEvent thisEvent)
{
text[whoGets].requestFocus();
but.setText("whos got="+whoGets);
whoGets = (whoGets+1)%text.length;
}
}
it simply makes an array of textfields, and every time you click on the button it knocks a counter up by 1 (modded by array.length to always keep it in the bounds of the array) then gets that text field to request the focus.. repeatedly hammer the button and watch the cursor track along each box
Bookmarks