When adding editable ComboBoxes dynamically to a pane layout and then requesting the focus via the requestFocus() method does not reliably display the flashing cursor; however, typing is still possible. The text highlighting also does not appear; however, it appears to still function as expected.
Additionally, invoking the ComboBox show() method after requesting the focus calls the onShown property despite no drop-down actually being visible. Subsequent clicking on the drop-down arrow UI element does not do anything.
Occasionally, the focus is correctly transferred and the flashing cursor, text highlighting, and pop-up are visible.
Below is an example:
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Dynamic extends Application {
@Override
public void start(Stage primaryStage) {
Button button = new Button();
HBox hbox = new HBox(button);
button.setOnAction(actionEvent -> {
ComboBox<String> newTf = new ComboBox<>();
newTf.setEditable(true);
newTf.setOnShown(event -> System.out.println("on shown"));
hbox.getChildren().add(newTf);
Platform.runLater(() -> {
newTf.requestFocus();
newTf.show();
});
});
Scene scene = new Scene(hbox);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Additionally, invoking the ComboBox show() method after requesting the focus calls the onShown property despite no drop-down actually being visible. Subsequent clicking on the drop-down arrow UI element does not do anything.
Occasionally, the focus is correctly transferred and the flashing cursor, text highlighting, and pop-up are visible.
Below is an example:
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Dynamic extends Application {
@Override
public void start(Stage primaryStage) {
Button button = new Button();
HBox hbox = new HBox(button);
button.setOnAction(actionEvent -> {
ComboBox<String> newTf = new ComboBox<>();
newTf.setEditable(true);
newTf.setOnShown(event -> System.out.println("on shown"));
hbox.getChildren().add(newTf);
Platform.runLater(() -> {
newTf.requestFocus();
newTf.show();
});
});
Scene scene = new Scene(hbox);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}