2 Replies Latest reply: Jan 17, 2013 7:50 PM by James_D RSS

    updateItem() method in table column

    964914
      The updateItem method of a cell value factory is called more than once for a particular row's cell(Single cell) when the tableview is rendered. Is this the expected behaviour or my cell factory class is wrong? Please let me know.

      thanks.
      public void updateItem(MyObject item, boolean empty) {
              super.updateItem(item, empty);
      System.out.println("Inside updateItem." + ((MyObject)item).getValue());
      }
      The above output prints the value of that cell for each row more than once. Is this the expected behavior ? The reason why i am asking this question is, I am creating some objects inside the updateItem() method and since this method is called multiple times, these objects are created once again causing duplicates and leaks.

      Also, I observe that once I scroll down to the last row in the tabe view and scroll up, again the update item method is invoked for the top rows which went to hide mode.

      Please clarify this behaviour
        • 1. Re: updateItem() method in table column
          964914
          Hope my question is clear. Any inputs will be of great help.

          Thanks.
          • 2. Re: updateItem() method in table column
            James_D
            961911 wrote:
            The updateItem method of a cell value factory is called more than once for a particular row's cell(Single cell) when the tableview is rendered. Is this the expected behaviour or my cell factory class is wrong? Please let me know.
            No real idea: but this is an implementation detail, and you shouldn't rely on the implementation of code outside your control anyway. Even if you know what it does in the current version of FX, there's no guarantee it will stay the same in future versions. The updateItem method is called as and when needed in order to display the cells in the table.
            The reason why i am asking this question is, I am creating some objects inside the updateItem() method and since this method is called multiple times, these objects are created once again causing duplicates and leaks.
            It's fine to create objects in this method; it's probably sensible not to let references to them escape. As long as you don't do that (and even in some cases where you do), you wouldn't be creating a memory leak. Since the purpose of the updateItem(...) method is to change the item which the cell is currently displaying, I can't see any reason why you'd want to pass the reference to an object with a longer life cycle anyway.