Hi,
I have one JTextField in one JPanel and I need to set focus in that JTextField on load of the application.
I have written following code for that:
for(int index = 0; index < panel.getComponentCount(); index++){
if(panel.getComponent(index) instanceof JTextField){
panel.setVisible(true);
final JTextField t = (JTextField) panel.getComponent(index);
//this is not working
boolean r = t.requestFocusInWindow();
System.out.println("rend focus: " +r);
//this is working
t.setBackground(Color.red);
break;
}
}
this.add(panel);
My method returns component having panel which has 4 components and I want to set focus only in the TextField. But above code its not working. Any idea?
Thanks in advance!