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

Events of controls inside a custom cellfactory of Dropbox are not triggered.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 8u20
    • 7u45, 8
    • javafx
    • Windows 7(Java 7 2.2.45 32bit & Java 8b129 32bit) , Mac OS X 10.9.1(Java 7 2.2.45)

      If a control, like a button is inside a combobox by using a cellfactory, is clicked. It doesn't respond to the events. So, if we have an scenario like the following, events won´t be triggered. There is no possibility to develop complex cells that could consume the mouse events.

      public class ComboBoxWithCellFactory extends Application {

          @Override
          public void start(Stage primaryStage) {
              ComboBox btn = new ComboBox();
              btn.setCellFactory(
                      new Callback<ListView<String>, ListCell<String>>() {
                          @Override
                          public ListCell<String> call(ListView<String> param) {
                              final ListCell<String> cell = new ListCell<String>() {
                                  {
                                      super.setPrefWidth(100);
                                  }

                                  @Override
                                  public void updateItem(String item, boolean empty) {
                                      super.updateItem(item, empty);
                                      if (item != null) {
                                          setText(item);
                                          Button btn = new Button("hola");
                                          btn.setOnAction(new EventHandler<ActionEvent>() {
                                              @Override
                                              public void handle(ActionEvent event) {
                                                  throw new UnsupportedOperationException("Not supported yet.");
                                              }
                                          });
                                          btn.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                              @Override
                                              public void handle(MouseEvent event) {
                                                  throw new UnsupportedOperationException("Not supported yet.");
                                              }
                                          });
                                          setGraphic(btn);
                                      } else {
                                          setText(null);
                                      }
                                  }
                              };
                              return cell;
                          }
                      });
              
              btn.getItems().add("mundo");

              StackPane root = new StackPane();
              root.getChildren().add(btn);

              Scene scene = new Scene(root, 300, 250);

              primaryStage.setTitle("Hola mundo!");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

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

      }

            jgiles Jonathan Giles
            dcirujanojfx Diego Cirujano (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: