Hey, its a vey simple question but m not able to achieve it doing what so ever.
I was trying the code,
public class Demo extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage stage)
{
stage.setTitle("Sample");
Scene scene = new Scene(new Group(), 450, 250);
BorderPane borderPane = new BorderPane();
borderPane = newScreen();
Group root = (Group)scene.getRoot();
root.getChildren().add(borderPane);
stage.setScene(scene);
stage.show();
}
public BorderPane newScreen()
{
BorderPane borderPane = new BorderPane();
GridPane gridPane = new GridPane();
Label cName = new Label("Company Name");
Label cAbout = new Label("About");
Label cContact = new Label("Contact");
final TextField tCompanyName = new TextField();
TextField tAbout = new TextField();
TextField tContactUs = new TextField();
Button add = new Button("Add");
tCompanyName.requestFocus();
gridPane.add(cName, 0, 0);
gridPane.add(tCompanyName, 1, 0);
gridPane.add(cAbout, 0, 1);
gridPane.add(tAbout, 1, 1);
gridPane.add(cContact, 0, 2);
gridPane.add(tContactUs, 1, 2);
gridPane.add(add, 0, 3);
gridPane.setAlignment(Pos.CENTER);
borderPane.setCenter(gridPane);
return borderPane;
}
}
I want that whenever the scene is loaded the focus must be on the first textField "tCompanyName", but requestFocus() doesnt seem to work. Can anyone explain me why ?
Edited by: abhinay_a on Feb 6, 2013 2:53 AM