I know that a node's requestFocus() method doesn't work until -
- it is visible,
- disableProperty() is set to false, and
- a scene owns it
but, if it is like this:
TextField tf = new TextField(), tf2 = new TextField(), tf3 = new TextField();
VBox holder = new VBox(5, tf, tf2, tf3);
TitledPane tp = new TitledPane("Testing",holder);
AnchorPane root = new AnchorPane(tp);
@Override
public void start(Stage primaryStage) {
tp.setExpanded(false);
tp.expandedProperty().addListener((c,o,n)->{
if(n)
tf.requestFocus();
});
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
then, all of the above is fulfilled but, still, textfield doesn't get focus if I expand the TitledPane.
Also, this doesn't seem to work:
Platform.runlater(()->tf.requestFocus());
Could anybody help me?