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

Values in Combobox with custom cell only selectable via keyboard

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 8u40
    • 8u5
    • javafx
    • None
    • OSX 10.9.3

      Values in a ComboBox with a callback that modifies the cell text is not selectable with the mouse. Execute the code below and try to select a value. It does not work with the mouse but it works using the keyboard. Additionally the selected value is displayed using a different string than displayed in the cell, i.e. it does not use the custom cell.

      package jfxtest;

      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.ComboBox;
      import javafx.scene.control.Label;
      import javafx.scene.control.ListCell;
      import javafx.scene.control.ListView;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.FlowPane;
      import javafx.scene.layout.GridPane;
      import javafx.scene.layout.Pane;
      import javafx.stage.Stage;
      import javafx.util.Callback;

      public class ComboTest extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception {
              FlowPane pane = new FlowPane();
              final ComboBox<Integer> combo = new ComboBox<>();
              combo.getItems().addAll(1, 2, 3);
              combo.setCellFactory(new Callback<ListView<Integer>, ListCell<Integer>>() {
                  @Override
                  public ListCell<Integer> call(ListView<Integer> param) {
                      return new ListCell<Integer>(){
                          @Override
                          protected void updateItem(Integer item, boolean empty) {
                              setText("#" + item);
                          }
                      };
                  }
              });
              pane.getChildren().add(combo);
              final Scene scene = new Scene(pane);
              primaryStage.setScene(scene);
              primaryStage.setTitle(getClass().getSimpleName());
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }

            jgiles Jonathan Giles
            rkruegerjfx Robert Krueger (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: