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

[TableView] TableView custom TableCell with ComboBoxes not editable.

XMLWordPrintable

      I have this sample that creates a TableView with a single column and a single line.

      I have overridden the cellfactory so that a ComboBox is showing when I want to edit the value.

      In JDK8, when you were double-clicking on the first cell, the ComboBox was showing properly and you could select an item.

      In JDK8u20 b17, the comboBox is showing (without the displayed items) but it is not possible to interract with it. It's impossible to select any item. This is a great regression. It's doing the same with ChoiceBox, DatePicker etc etc. It is because I want to show (display the list) directly and I call "editor.show()". This is causing the problem.

      Step to reproduce:
      Run this sample:
      "
      import java.util.Arrays;
      import java.util.List;
      import javafx.application.Application;
      import static javafx.application.Application.launch;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.ComboBox;
      import javafx.scene.control.TableCell;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.stage.Stage;
      import javafx.util.Callback;

      public class TableViewSample extends Application {

          private TableView<String> table = new TableView<>();

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

          private final List<String> countryList = Arrays.asList("China", "France", "New Zealand",
                  "United States", "Germany", "Canada");

          @Override
          public void start(Stage stage) {
              Scene scene = new Scene(new Group());

              ComboBox<String> comboBox = new ComboBox<>();
              comboBox.setVisibleRowCount(5);

              stage.setTitle("Table View Sample");
              stage.setWidth(450);
              stage.setHeight(550);

              table.setEditable(true);
              table.getSelectionModel().setCellSelectionEnabled(true);

              TableColumn firstNameCol = new TableColumn("First Name");
              firstNameCol.setMinWidth(100);
              firstNameCol.setCellFactory(new Callback() {

                  @Override
                  public Object call(Object param) {
                      return new TableCell<String, String>() {
                          /**
                           * {@inheritDoc}
                           */
                          @Override
                          public void startEdit() {
                              super.startEdit();
                              setText(null);
                              
                              setGraphic(comboBox);
                              ObservableList<String> items = FXCollections.observableList(countryList);
                              comboBox.setItems(items);
                              comboBox.setValue(countryList.get(0));


                              comboBox.show(); // This call is causing the trouble.
                          }

                          /**
                           * {@inheritDoc}
                           */
                          @Override
                          public void cancelEdit() {
                              super.cancelEdit();

                              setText("test");
                              setGraphic(null);
                          }
                      };
                  }
              });

              table.setItems(FXCollections.observableArrayList("testData"));
              table.getColumns().addAll(firstNameCol);

              ((Group) scene.getRoot()).getChildren().addAll(table);

              stage.setScene(scene);
              stage.show();
          }
      }
      "

      Double click on the very first cell (even if nothing is shown).
      A ComboBox appears. It's working nice in JDK8 but not in JDK8u20 b17.

            dgrieve David Grieve
            shadzic Samir Hadzic
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: