sshahine / JFoenix

JavaFX Material Design Library
MIT License
6.29k stars 1.06k forks source link

JFXRippler not working when deriving from JFXTreeCell/JFXListCell #1152

Open Searen1984 opened 3 years ago

Searen1984 commented 3 years ago

I want to fill a JFXTreeView and a JFXListView with own nodes or own text for example through a StringConverter. However, if I do this for a JFXListView:

private JFXListView<User> listView;

private static final class User extends RecursiveTreeObject<User> {
    final StringProperty userName;
    final SimpleObjectProperty<LocalDate> age;
    final StringProperty department;
    final SimpleObjectProperty<HouseTypes> type;

    User(String department, LocalDate age, String userName, HouseTypes type) {
      this.department = new SimpleStringProperty(department);
      this.userName = new SimpleStringProperty(userName);
      this.age = new SimpleObjectProperty<>(age);
      this.type = new SimpleObjectProperty<>(type);
    }
  }

private void initListView() {
    listView.setCellFactory(new Callback<ListView<User>, ListCell<User>>() {
      @Override
      public ListCell<User> call(ListView<User> param) {
          JFXListCell<User> cell = new JFXListCell<>(){
              @Override
              public void updateItem(User item, boolean empty) {
                  super.updateItem(item, empty);
                  if(item != null && !empty) {
                    Text header = new Text(item.userName.get());
                    Text subtext = new Text(item.department.get());
                    VBox container = new VBox(header, subtext);
                    setGraphic(container);
                  }
              }
          };

          cell.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);

          return cell;
      }
    });

    User user1 = new User(COMPUTER_DEPARTMENT, LocalDate.of(1990, 3, 2), "CD 1", HouseTypes.BIG);
    User user2 = new User(SALES_DEPARTMENT, LocalDate.of(1990, 7, 22), "Employee 1", HouseTypes.SMALL);
    User user3 = new User(SALES_DEPARTMENT, LocalDate.of(1987, 1, 12), "Employee 2", HouseTypes.BIG);

    listView.getItems().addAll(user1, user2, user3);
  }

or this for a JFXTreeView:

private JFXTreeView<String> treeView;

private void initTreeView() {
    TreeItem<String> root = new TreeItem<>();

    TreeItem<String> string1 = new TreeItem<>();
    string1.setValue("string1");

    root.getChildren().addAll(string1);

    treeView.setRoot(root);
    treeView.setShowRoot(false);

    treeView.setCellFactory(view -> new JFXTreeCell<String>() {
      @Override
      public void updateItem(String item, boolean empty) {
        super.updateItem(item, empty);
        if (item != null && !empty) {
          setText("string2");
        }
      }
    });
  }

the rippler effect is gone when clicking a row the first time. However, if a row is selected the rippler effect is there. The two code snippets use setGraphic() andsetText() to show that both erase the rippler effect for both views. It should be mentioned that using getTreeItem().setGraphic() works fine for the JFXTreeView. Am I doing something wrong or is it a bug? I am using JFoenix 9.0.10 and OpenJDK 11. Thanks for your support.