5 Replies Latest reply on Nov 27, 2012 1:58 PM by edward17

    ListView misbehaving...

      OK, this is VERY troubling...

      I have a ListView tied to a list of 25 items.

      All is well until I scroll to view the bottom half of the list. At that point:

      Items get reordered inthe display
      Items at top reappear at odd places in the bottom half of the list

      I can never see the 25 unique items, as older items get redisplayed instead

      I use a custom Cell Factory:
          private static class SelectRowCell extends ListCell<SelectRow> {
              protected void updateItem(SelectRow item, boolean empty) {
                  super.updateItem(item, empty);
                  HBox cell = new HBox();
                  if (!empty) {
                      boolean isDupe = false;
                      if(!item.isExporting() && item.getShortTitle() != null && !item.getShortTitle().isEmpty()) {
                          isDupe = TemplateDao.getInstance().dupeCheck(item.getShortTitle());
                      CheckBox cb = new CheckBox();
                      String data = item.toCSV();
                      TextField row = new TextField(data);
                      if(isDupe) {
                      HBox.setHgrow(row, Priority.ALWAYS);
                      cell.getChildren().addAll(cb, row);
      Am I doing something wrong?

      Help! I am only a few weeks away from a production rollout of a commercial product!
        • 1. Re: ListView misbehaving...
          It's always a good idea to provide a complete working test case that people can play with.
          • 2. Re: ListView misbehaving...
            I can't seem to repeat outside my code.

            What I see is that when the observable list is changed, for each entry the cell factory gets called. However whne it gets a row or two past what is visible, instead of continuing to iterate thru the list, it starts again at the top. when I scroll down, I see the repeats. whne I scroll back up, it almost looks like it wrapped in that the old first entry is no longer the first entry?

            Suggest something to check?

            (I did verify that tyhe Observable List is valid both before and after - i.e. all unique items.)
            • 3. Re: ListView misbehaving...
              MiPa is correct... not enough of your code is visible for anyone to offer real help. I would guess your problem lies at least partially outside that section of code. One thing I will note from what I can see though, is that you are doing a bi-directional property bind on that 'item' variable. If the same instance of that SelectRow object is being inadvertently added in multiple places, you could end up with lots of indirectly linked checkboxes. I'm not sure what duplication looks like in your application, but that's the only advice I can think to offer without seeing more.

              I'll also note that it's probably not advisable to be using JavaFX in commercial systems just yet; particularly when you're running into fundamental issues like this.
              • 4. Re: ListView misbehaving...
                OK finally figured it out,

                The ListCell implementation I was using extended another class. That class overrode hashCode(). The implementation of hashCode() was faulty (calculated the hash on a non unique field). This resulted in the odd behavior.

                Once I fixed the hashCode() implementation the problem went away.

                wasn't that fun?
                • 5. Re: ListView misbehaving...
                  See my last post