Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8089753

Requesting Focus on Dynamically Added ComboBoxes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u45, 8u60
    • javafx
    • None
    • Windows 8.1 x64

      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);
      }
      }

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported: