• Post Reply Bookmark Topic Watch Topic
  • New Topic

requestFocus() is not working??

 
kishor patankar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!!! Friends,
Any body know what is the problem with my following code. The focus had been not set to the second textfield.
thanks,
Kishor
import java.awt.*;
import java.awt.event.*;
public class Test extends Frame
{
TextField theFld1 = new TextField(10);
TextField theFld2 = new TextField(10);
public static void main (String args[])
{
new Test();
}
public Test()
{
setLayout(new FlowLayout());
setSize(800,600);
theFld2.requestFocus();
add(theFld1);
add(theFld2);
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle frameDim = getBounds();
setLocation((screenDim.width - frameDim.width) / 2,(screenDim.height - frameDim.height) / 2);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
dispose();
System.gc();
System.exit(0);
}
});
}
}
 
Helmut Lerch
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy,
write the "theFld2.requestFocus();" after "setVisible(true);" and everything works fine.
 
kishor patankar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Helmut Lerch, its work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!